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
88aef766
Commit
88aef766
authored
Jan 11, 2013
by
Sascha Cunz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement analog for 'git checkout --branch xxx ...'
parent
132c2db6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletions
+34
-1
include/git2/clone.h
+3
-0
src/clone.c
+31
-1
No files found.
include/git2/clone.h
View file @
88aef766
...
...
@@ -57,6 +57,8 @@ GIT_BEGIN_DECL
* the origin remote before the fetch is initiated.
* - `remote_autotag` may be used to specify the autotag setting before the
* initial fetch.
* - `checkout_branch` gives the name of the branch to checkout. NULL means
* use the remote's HEAD.
*/
typedef
struct
git_clone_options
{
...
...
@@ -76,6 +78,7 @@ typedef struct git_clone_options {
git_transport
*
transport
;
git_remote_callbacks
*
remote_callbacks
;
git_remote_autotag_option_t
remote_autotag
;
const
char
*
checkout_branch
;
}
git_clone_options
;
#define GIT_CLONE_OPTIONS_VERSION 1
...
...
src/clone.c
View file @
88aef766
...
...
@@ -260,6 +260,31 @@ cleanup:
return
retcode
;
}
static
int
update_head_to_branch
(
git_repository
*
repo
,
const
git_clone_options
*
options
)
{
int
retcode
;
git_buf
remote_branch_name
=
GIT_BUF_INIT
;
git_reference
*
remote_ref
=
NULL
;
assert
(
options
->
checkout_branch
);
if
((
retcode
=
git_buf_printf
(
&
remote_branch_name
,
GIT_REFS_REMOTES_DIR
"%s/%s"
,
options
->
remote_name
,
options
->
checkout_branch
))
<
0
)
goto
cleanup
;
if
((
retcode
=
git_reference_lookup
(
&
remote_ref
,
repo
,
git_buf_cstr
(
&
remote_branch_name
)))
<
0
)
goto
cleanup
;
retcode
=
update_head_to_new_branch
(
repo
,
git_reference_target
(
remote_ref
),
options
->
checkout_branch
);
cleanup:
git_reference_free
(
remote_ref
);
return
retcode
;
}
/*
* submodules?
*/
...
...
@@ -331,8 +356,13 @@ static int setup_remotes_and_fetch(
options
->
fetch_progress_payload
))
{
/* Create "origin/foo" branches for all remote branches */
if
(
!
git_remote_update_tips
(
origin
))
{
/* Point HEAD to the requested branch */
if
(
options
->
checkout_branch
)
{
if
(
!
update_head_to_branch
(
repo
,
options
))
retcode
=
0
;
}
/* Point HEAD to the same ref as the remote's head */
if
(
!
update_head_to_remote
(
repo
,
origin
))
{
else
if
(
!
update_head_to_remote
(
repo
,
origin
))
{
retcode
=
0
;
}
}
...
...
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