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
b9e7e2b4
Commit
b9e7e2b4
authored
Dec 14, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move non-options back out of options struct
parent
0015b587
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
58 deletions
+60
-58
examples/network/clone.c
+5
-6
include/git2/clone.h
+10
-8
src/clone.c
+12
-5
tests-clar/clone/network.c
+11
-13
tests-clar/clone/nonetwork.c
+14
-15
tests-clar/fetchhead/network.c
+4
-5
tests-clar/network/fetch.c
+4
-6
No files found.
examples/network/clone.c
View file @
b9e7e2b4
...
...
@@ -66,6 +66,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
{
progress_data
pd
;
git_repository
*
cloned_repo
=
NULL
;
git_remote
*
origin
;
git_clone_options
clone_opts
=
GIT_CLONE_OPTIONS_INIT
;
git_checkout_opts
checkout_opts
=
GIT_CHECKOUT_OPTS_INIT
;
const
char
*
url
=
argv
[
1
];
...
...
@@ -87,23 +88,21 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts
.
progress_payload
=
&
pd
;
// Create the origin remote, and set up for auth
error
=
git_remote_new
(
&
clone_opts
.
origin_remote
,
NULL
,
"origin"
,
url
,
GIT_REMOTE_DEFAULT_FETCH
);
error
=
git_remote_new
(
&
origin
,
NULL
,
"origin"
,
url
,
GIT_REMOTE_DEFAULT_FETCH
);
if
(
error
!=
0
)
{
const
git_error
*
err
=
giterr_last
();
if
(
err
)
printf
(
"ERROR %d: %s
\n
"
,
err
->
klass
,
err
->
message
);
else
printf
(
"ERROR %d: no detailed info
\n
"
,
error
);
return
error
;
}
git_remote_set_cred_acquire_cb
(
clone_opts
.
origin_remote
,
cred_acquire
,
NULL
);
git_remote_set_cred_acquire_cb
(
origin
,
cred_acquire
,
NULL
);
// Do the clone
clone_opts
.
out
=
&
cloned_repo
;
clone_opts
.
local_path
=
path
;
clone_opts
.
checkout_opts
=
&
checkout_opts
;
clone_opts
.
fetch_progress_cb
=
&
fetch_progress
;
clone_opts
.
fetch_progress_payload
=
&
pd
;
error
=
git_clone
(
&
clone_opts
);
git_remote_free
(
clone_opts
.
origin_remote
);
error
=
git_clone
(
&
clone
d_repo
,
origin
,
path
,
&
clone
_opts
);
git_remote_free
(
origin
);
printf
(
"
\n
"
);
if
(
error
!=
0
)
{
const
git_error
*
err
=
giterr_last
();
...
...
include/git2/clone.h
View file @
b9e7e2b4
...
...
@@ -30,9 +30,6 @@ GIT_BEGIN_DECL
*
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
*
* - `out` is a pointer that receives the resulting repository object
* - `origin_remote` is a remote which will act as the initial fetch source
* - `local_path` is local directory to clone into
* - `bare` should be set to zero to create a standard repo, non-zero for
* a bare repo
* - `fetch_progress_cb` is optional callback for fetch progress. Be aware that
...
...
@@ -46,9 +43,6 @@ GIT_BEGIN_DECL
typedef
struct
git_clone_options
{
unsigned
int
version
;
git_repository
**
out
;
git_remote
*
origin_remote
;
const
char
*
local_path
;
int
bare
;
git_transfer_progress_callback
fetch_progress_cb
;
void
*
fetch_progress_payload
;
...
...
@@ -62,11 +56,19 @@ typedef struct git_clone_options {
* Clone a remote repository, and checkout the branch pointed to by the remote
* HEAD.
*
* @param options configuration options for the clone
* @param out pointer that will receive the resulting repository object
* @param origin_remote a remote which will act as the initial fetch source
* @param local_path local directory to clone to
* @param options configuration options for the clone. If NULL, the function
* works as though GIT_OPTIONS_INIT were passed.
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* about the error)
*/
GIT_EXTERN
(
int
)
git_clone
(
git_clone_options
*
options
);
GIT_EXTERN
(
int
)
git_clone
(
git_repository
**
out
,
git_remote
*
origin
,
const
char
*
local_path
,
const
git_clone_options
*
options
);
/** @} */
GIT_END_DECL
...
...
src/clone.c
View file @
b9e7e2b4
...
...
@@ -355,16 +355,23 @@ static int clone_internal(
return
retcode
;
}
int
git_clone
(
git_clone_options
*
options
)
int
git_clone
(
git_repository
**
out
,
git_remote
*
origin
,
const
char
*
local_path
,
const
git_clone_options
*
options
)
{
assert
(
options
&&
options
->
out
&&
options
->
origin_remote
&&
options
->
local_path
);
git_clone_options
dummy_options
=
GIT_CLONE_OPTIONS_INIT
;
assert
(
out
&&
origin
&&
local_path
);
if
(
!
options
)
options
=
&
dummy_options
;
GITERR_CHECK_VERSION
(
options
,
GIT_CLONE_OPTIONS_VERSION
,
"git_clone_options"
);
return
clone_internal
(
o
ptions
->
o
ut
,
o
ptions
->
origin_remote
,
options
->
local_path
,
out
,
o
rigin
,
local_path
,
options
->
fetch_progress_cb
,
options
->
fetch_progress_payload
,
options
->
checkout_opts
,
...
...
tests-clar/clone/network.c
View file @
b9e7e2b4
...
...
@@ -9,6 +9,7 @@ CL_IN_CATEGORY("network")
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
static
git_repository
*
g_repo
;
static
git_remote
*
g_origin
;
static
git_clone_options
g_options
;
void
test_clone_network__initialize
(
void
)
...
...
@@ -17,14 +18,12 @@ void test_clone_network__initialize(void)
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
out
=
&
g_repo
;
g_options
.
local_path
=
"./foo"
;
cl_git_pass
(
git_remote_new
(
&
g_options
.
origin_remote
,
NULL
,
"origin"
,
LIVE_REPO_URL
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_pass
(
git_remote_new
(
&
g_origin
,
NULL
,
"origin"
,
LIVE_REPO_URL
,
GIT_REMOTE_DEFAULT_FETCH
));
}
void
test_clone_network__cleanup
(
void
)
{
git_remote_free
(
g_o
ptions
.
origin_remote
);
git_remote_free
(
g_o
rigin
);
}
static
void
cleanup_repository
(
void
*
path
)
...
...
@@ -43,7 +42,7 @@ void test_clone_network__network_full(void)
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_assert
(
!
git_repository_is_bare
(
g_repo
));
cl_git_pass
(
git_remote_load
(
&
origin
,
g_repo
,
"origin"
));
...
...
@@ -58,7 +57,7 @@ void test_clone_network__network_bare(void)
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
g_options
.
bare
=
true
;
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_assert
(
git_repository_is_bare
(
g_repo
));
cl_git_pass
(
git_remote_load
(
&
origin
,
g_repo
,
"origin"
));
...
...
@@ -70,8 +69,7 @@ void test_clone_network__cope_with_already_existing_directory(void)
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
p_mkdir
(
"./foo"
,
GIT_DIR_MODE
);
cl_git_pass
(
git_clone
(
&
g_options
));
git_repository_free
(
g_repo
);
g_repo
=
NULL
;
cl_git_pass
(
git_clone
(
&
g_repo
,
g_origin
,
"./foo"
,
&
g_options
));
}
void
test_clone_network__empty_repository
(
void
)
...
...
@@ -80,10 +78,10 @@ void test_clone_network__empty_repository(void)
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
git_remote_free
(
g_o
ptions
.
origin_remote
);
cl_git_pass
(
git_remote_new
(
&
g_o
ptions
.
origin_remote
,
NULL
,
"origin"
,
LIVE_EMPTYREPO_URL
,
GIT_REMOTE_DEFAULT_FETCH
));
git_remote_free
(
g_o
rigin
);
cl_git_pass
(
git_remote_new
(
&
g_o
rigin
,
NULL
,
"origin"
,
LIVE_EMPTYREPO_URL
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_assert_equal_i
(
true
,
git_repository_is_empty
(
g_repo
));
cl_assert_equal_i
(
true
,
git_repository_head_orphan
(
g_repo
));
...
...
@@ -100,7 +98,7 @@ void test_clone_network__can_prevent_the_checkout_of_a_standard_repo(void)
git_buf
path
=
GIT_BUF_INIT
;
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_git_pass
(
git_buf_joinpath
(
&
path
,
git_repository_workdir
(
g_repo
),
"master.txt"
));
cl_assert_equal_i
(
false
,
git_path_isfile
(
git_buf_cstr
(
&
path
)));
...
...
@@ -139,7 +137,7 @@ void test_clone_network__can_checkout_a_cloned_repo(void)
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_git_pass
(
git_buf_joinpath
(
&
path
,
git_repository_workdir
(
g_repo
),
"master.txt"
));
cl_assert_equal_i
(
true
,
git_path_isfile
(
git_buf_cstr
(
&
path
)));
...
...
tests-clar/clone/nonetwork.c
View file @
b9e7e2b4
...
...
@@ -6,6 +6,7 @@
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
static
git_clone_options
g_options
;
static
git_remote
*
g_origin
;
static
git_repository
*
g_repo
;
void
test_clone_nonetwork__initialize
(
void
)
...
...
@@ -14,14 +15,12 @@ void test_clone_nonetwork__initialize(void)
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
out
=
&
g_repo
;
g_options
.
local_path
=
"./foo"
;
cl_git_pass
(
git_remote_new
(
&
g_options
.
origin_remote
,
NULL
,
"origin"
,
cl_git_fixture_url
(
"testrepo.git"
),
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_pass
(
git_remote_new
(
&
g_origin
,
NULL
,
"origin"
,
cl_git_fixture_url
(
"testrepo.git"
),
GIT_REMOTE_DEFAULT_FETCH
));
}
void
test_clone_nonetwork__cleanup
(
void
)
{
git_remote_free
(
g_o
ptions
.
origin_remote
);
git_remote_free
(
g_o
rigin
);
}
static
void
cleanup_repository
(
void
*
path
)
...
...
@@ -37,38 +36,38 @@ static void cleanup_repository(void *path)
void
test_clone_nonetwork__bad_url
(
void
)
{
/* Clone should clean up the mess if the URL isn't a git repository */
git_remote_free
(
g_o
ptions
.
origin_remote
);
cl_git_pass
(
git_remote_new
(
&
g_o
ptions
.
origin_remote
,
NULL
,
"origin"
,
"not_a_repo"
,
GIT_REMOTE_DEFAULT_FETCH
));
git_remote_free
(
g_o
rigin
);
cl_git_pass
(
git_remote_new
(
&
g_o
rigin
,
NULL
,
"origin"
,
"not_a_repo"
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_fail
(
git_clone
(
&
g_options
));
cl_git_fail
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_assert
(
!
git_path_exists
(
"./foo"
));
g_options
.
bare
=
true
;
cl_git_fail
(
git_clone
(
&
g_options
));
cl_git_fail
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
cl_assert
(
!
git_path_exists
(
"./foo"
));
}
void
test_clone_nonetwork__local
(
void
)
{
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
}
void
test_clone_nonetwork__local_absolute_path
(
void
)
{
const
char
*
local_src
=
cl_fixture
(
"testrepo.git"
);
git_remote_free
(
g_o
ptions
.
origin_remote
);
cl_git_pass
(
git_remote_new
(
&
g_o
ptions
.
origin_remote
,
NULL
,
"origin"
,
local_src
,
GIT_REMOTE_DEFAULT_FETCH
));
git_remote_free
(
g_o
rigin
);
cl_git_pass
(
git_remote_new
(
&
g_o
rigin
,
NULL
,
"origin"
,
local_src
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
}
void
test_clone_nonetwork__local_bare
(
void
)
{
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
g_options
.
bare
=
true
;
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
}
void
test_clone_nonetwork__fail_when_the_target_is_a_file
(
void
)
...
...
@@ -76,7 +75,7 @@ void test_clone_nonetwork__fail_when_the_target_is_a_file(void)
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_mkfile
(
"./foo"
,
"Bar!"
);
cl_git_fail
(
git_clone
(
&
g_options
));
cl_git_fail
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
}
void
test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory
(
void
)
...
...
@@ -85,5 +84,5 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo
p_mkdir
(
"./foo"
,
GIT_DIR_MODE
);
cl_git_mkfile
(
"./foo/bar"
,
"Baz!"
);
cl_git_fail
(
git_clone
(
&
g_options
));
cl_git_fail
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
}
tests-clar/fetchhead/network.c
View file @
b9e7e2b4
...
...
@@ -10,6 +10,7 @@ CL_IN_CATEGORY("network")
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
static
git_repository
*
g_repo
;
static
git_remote
*
g_origin
;
static
git_clone_options
g_options
;
void
test_fetchhead_network__initialize
(
void
)
...
...
@@ -18,14 +19,12 @@ void test_fetchhead_network__initialize(void)
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
out
=
&
g_repo
;
g_options
.
local_path
=
"./foo"
;
cl_git_pass
(
git_remote_new
(
&
g_options
.
origin_remote
,
NULL
,
"origin"
,
LIVE_REPO_URL
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_pass
(
git_remote_new
(
&
g_origin
,
NULL
,
"origin"
,
LIVE_REPO_URL
,
GIT_REMOTE_DEFAULT_FETCH
));
}
void
test_fetchhead_network__cleanup
(
void
)
{
git_remote_free
(
g_o
ptions
.
origin_remote
);
git_remote_free
(
g_o
rigin
);
}
static
void
cleanup_repository
(
void
*
path
)
...
...
@@ -43,7 +42,7 @@ static void fetchhead_test_clone(void)
{
cl_set_cleanup
(
&
cleanup_repository
,
"./foo"
);
cl_git_pass
(
git_clone
(
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_
repo
,
g_origin
,
"./foo"
,
&
g_
options
));
}
static
void
fetchhead_test_fetch
(
const
char
*
fetchspec
,
const
char
*
expected_fetchhead
)
...
...
tests-clar/network/fetch.c
View file @
b9e7e2b4
...
...
@@ -87,15 +87,13 @@ void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_dat
{
git_repository
*
_repository
;
bool
invoked
=
false
;
git_remote
*
remote
;
git_remote
*
remote
,
*
origin
;
git_clone_options
opts
=
GIT_CLONE_OPTIONS_INIT
;
opts
.
out
=
&
_repository
;
opts
.
local_path
=
"./fetch/lg2"
;
opts
.
bare
=
true
;
cl_git_pass
(
git_remote_new
(
&
o
pts
.
origin_remote
,
NULL
,
"origin"
,
"https://github.com/libgit2/TestGitRepository.git"
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_pass
(
git_remote_new
(
&
o
rigin
,
NULL
,
"origin"
,
"https://github.com/libgit2/TestGitRepository.git"
,
GIT_REMOTE_DEFAULT_FETCH
));
cl_git_pass
(
git_clone
(
&
opts
));
cl_git_pass
(
git_clone
(
&
_repository
,
origin
,
"./fetch/lg2"
,
&
opts
));
git_repository_free
(
_repository
);
cl_git_pass
(
git_repository_open
(
&
_repository
,
"./fetch/lg2"
));
...
...
@@ -113,6 +111,6 @@ void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_dat
git_remote_disconnect
(
remote
);
git_remote_free
(
remote
);
git_remote_free
(
o
pts
.
origin_remote
);
git_remote_free
(
o
rigin
);
git_repository_free
(
_repository
);
}
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