Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
121b2673
Commit
121b2673
authored
Dec 23, 2013
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clone: add flags to override whether to perform a local clone
parent
a0b5f785
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
1 deletions
+72
-1
include/git2/clone.h
+7
-0
src/clone.c
+24
-1
src/clone.h
+12
-0
tests/clone/local.c
+29
-0
No files found.
include/git2/clone.h
View file @
121b2673
...
...
@@ -23,6 +23,12 @@
*/
GIT_BEGIN_DECL
typedef
enum
{
GIT_CLONE_LOCAL_AUTO
,
GIT_CLONE_LOCAL
,
GIT_CLONE_NO_LOCAL
,
}
git_clone_local_t
;
/**
* Clone options structure
*
...
...
@@ -57,6 +63,7 @@ typedef struct git_clone_options {
int
bare
;
int
ignore_cert_errors
;
git_clone_local_t
local
;
const
char
*
remote_name
;
const
char
*
checkout_branch
;
git_signature
*
signature
;
...
...
src/clone.c
View file @
121b2673
...
...
@@ -347,6 +347,29 @@ cleanup:
return
error
;
}
int
git_clone__should_clone_local
(
const
char
*
url
,
git_clone_local_t
local
)
{
const
char
*
path
;
int
is_url
;
if
(
local
==
GIT_CLONE_NO_LOCAL
)
return
false
;
is_url
=
!
git__prefixcmp
(
url
,
"file://"
);
if
(
is_url
&&
local
!=
GIT_CLONE_LOCAL
)
return
false
;
path
=
url
;
if
(
is_url
)
path
=
url
+
strlen
(
"file://"
);
if
((
git_path_exists
(
path
)
&&
git_path_isdir
(
path
))
&&
local
!=
GIT_CLONE_NO_LOCAL
)
return
true
;
return
false
;
}
int
git_clone
(
git_repository
**
out
,
const
char
*
url
,
...
...
@@ -381,7 +404,7 @@ int git_clone(
return
error
;
if
(
!
(
error
=
create_and_configure_origin
(
&
origin
,
repo
,
url
,
&
options
)))
{
if
(
git_
path_exists
(
url
)
&&
git_path_isdir
(
ur
l
))
{
if
(
git_
clone__should_clone_local
(
url
,
options
.
loca
l
))
{
error
=
git_clone_local_into
(
repo
,
origin
,
&
options
.
checkout_opts
,
options
.
checkout_branch
,
options
.
signature
);
...
...
src/clone.h
0 → 100644
View file @
121b2673
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_clone_h__
#define INCLUDE_clone_h__
extern
int
git_clone__should_clone_local
(
const
char
*
url
,
git_clone_local_t
local
);
#endif
tests/clone/local.c
0 → 100644
View file @
121b2673
#include "clar_libgit2.h"
#include "git2/clone.h"
#include "clone.h"
#include "buffer.h"
void
assert_clone
(
const
char
*
path
,
git_clone_local_t
opt
,
int
val
)
{
cl_assert_equal_i
(
val
,
git_clone__should_clone_local
(
path
,
opt
));
}
void
test_clone_local__should_clone_local
(
void
)
{
git_buf
buf
=
GIT_BUF_INIT
;
const
char
*
path
;
/* we use a fixture path because it needs to exist for us to want to clone */
cl_git_pass
(
git_buf_printf
(
&
buf
,
"file://%s"
,
cl_fixture
(
"testrepo.git"
)));
cl_assert_equal_i
(
false
,
git_clone__should_clone_local
(
buf
.
ptr
,
GIT_CLONE_LOCAL_AUTO
));
cl_assert_equal_i
(
true
,
git_clone__should_clone_local
(
buf
.
ptr
,
GIT_CLONE_LOCAL
));
cl_assert_equal_i
(
false
,
git_clone__should_clone_local
(
buf
.
ptr
,
GIT_CLONE_NO_LOCAL
));
git_buf_free
(
&
buf
);
path
=
cl_fixture
(
"testrepo.git"
);
cl_assert_equal_i
(
true
,
git_clone__should_clone_local
(
path
,
GIT_CLONE_LOCAL_AUTO
));
cl_assert_equal_i
(
true
,
git_clone__should_clone_local
(
path
,
GIT_CLONE_LOCAL
));
cl_assert_equal_i
(
false
,
git_clone__should_clone_local
(
path
,
GIT_CLONE_NO_LOCAL
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment