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
730df6d0
Commit
730df6d0
authored
Jan 02, 2013
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include checkout options inline
parent
c07b52df
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
12 deletions
+22
-12
examples/network/clone.c
+1
-1
include/git2/clone.h
+4
-4
src/clone.c
+5
-2
tests-clar/clone/network.c
+8
-5
tests-clar/clone/nonetwork.c
+4
-0
No files found.
examples/network/clone.c
View file @
730df6d0
...
...
@@ -94,10 +94,10 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
clone_opts
.
checkout_opts
=
&
checkout_opts
;
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
checkout_opts
.
progress_cb
=
checkout_progress
;
checkout_opts
.
progress_payload
=
&
pd
;
clone_opts
.
checkout_opts
=
checkout_opts
;
clone_opts
.
fetch_progress_cb
=
&
fetch_progress
;
clone_opts
.
fetch_progress_payload
=
&
pd
;
clone_opts
.
cred_acquire_cb
=
cred_acquire
;
...
...
include/git2/clone.h
View file @
730df6d0
...
...
@@ -31,14 +31,14 @@ GIT_BEGIN_DECL
*
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
*
* - `checkout_opts` is options for the checkout step. To disable checkout,
* set the `checkout_strategy` to GIT_CHECKOUT_DEFAULT.
* - `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
* this is called inline with network and indexing operations, so performance
* may be affected.
* - `fetch_progress_payload` is payload for fetch_progress_cb
* - `checkout_opts` is options for the checkout step. If NULL, no checkout is
* performed
*
* ** "origin" remote options: **
* - `remote_name` is the name given to the "origin" remote. The default is
...
...
@@ -62,10 +62,10 @@ GIT_BEGIN_DECL
typedef
struct
git_clone_options
{
unsigned
int
version
;
git_checkout_opts
checkout_opts
;
int
bare
;
git_transfer_progress_callback
fetch_progress_cb
;
void
*
fetch_progress_payload
;
git_checkout_opts
*
checkout_opts
;
const
char
*
remote_name
;
const
char
*
pushurl
;
...
...
@@ -79,7 +79,7 @@ typedef struct git_clone_options {
}
git_clone_options
;
#define GIT_CLONE_OPTIONS_VERSION 1
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION}
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION
, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE}
}
/**
* Clone a remote repository, and checkout the branch pointed to by the remote
...
...
src/clone.c
View file @
730df6d0
...
...
@@ -362,6 +362,9 @@ static bool should_checkout(
if
(
!
opts
)
return
false
;
if
(
opts
->
checkout_strategy
==
GIT_CHECKOUT_DEFAULT
)
return
false
;
return
!
git_repository_head_orphan
(
repo
);
}
...
...
@@ -406,8 +409,8 @@ int git_clone(
}
}
if
(
!
retcode
&&
should_checkout
(
repo
,
normOptions
.
bare
,
normOptions
.
checkout_opts
))
retcode
=
git_checkout_head
(
*
out
,
normOptions
.
checkout_opts
);
if
(
!
retcode
&&
should_checkout
(
repo
,
normOptions
.
bare
,
&
normOptions
.
checkout_opts
))
retcode
=
git_checkout_head
(
*
out
,
&
normOptions
.
checkout_opts
);
return
retcode
;
}
tests-clar/clone/network.c
View file @
730df6d0
...
...
@@ -13,10 +13,14 @@ static git_clone_options g_options;
void
test_clone_network__initialize
(
void
)
{
git_checkout_opts
dummy_opts
=
GIT_CHECKOUT_OPTS_INIT
;
g_repo
=
NULL
;
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
checkout_opts
=
dummy_opts
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
}
static
void
cleanup_repository
(
void
*
path
)
...
...
@@ -88,6 +92,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"
);
g_options
.
checkout_opts
.
checkout_strategy
=
0
;
cl_git_pass
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
cl_git_pass
(
git_buf_joinpath
(
&
path
,
git_repository_workdir
(
g_repo
),
"master.txt"
));
...
...
@@ -112,16 +117,14 @@ static void fetch_progress(const git_transfer_progress *stats, void *payload)
void
test_clone_network__can_checkout_a_cloned_repo
(
void
)
{
git_checkout_opts
opts
=
GIT_CHECKOUT_OPTS_INIT
;
git_buf
path
=
GIT_BUF_INIT
;
git_reference
*
head
;
bool
checkout_progress_cb_was_called
=
false
,
fetch_progress_cb_was_called
=
false
;
opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
opts
.
progress_cb
=
&
checkout_progress
;
opts
.
progress_payload
=
&
checkout_progress_cb_was_called
;
g_options
.
checkout_opts
=
&
opts
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
g_options
.
checkout_opts
.
progress_cb
=
&
checkout_progress
;
g_options
.
checkout_opts
.
progress_payload
=
&
checkout_progress_cb_was_called
;
g_options
.
fetch_progress_cb
=
&
fetch_progress
;
g_options
.
fetch_progress_payload
=
&
fetch_progress_cb_was_called
;
...
...
tests-clar/clone/nonetwork.c
View file @
730df6d0
...
...
@@ -10,10 +10,14 @@ static git_repository *g_repo;
void
test_clone_nonetwork__initialize
(
void
)
{
git_checkout_opts
dummy_opts
=
GIT_CHECKOUT_OPTS_INIT
;
g_repo
=
NULL
;
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
checkout_opts
=
dummy_opts
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
}
static
void
cleanup_repository
(
void
*
path
)
...
...
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