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
6bb35878
Commit
6bb35878
authored
Feb 08, 2021
by
Alexander Ovchinnikov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clone: set refs/remotes/origin/HEAD to default branch when branch is specified, attempt 2
parent
8643b524
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
+22
-7
src/clone.c
+14
-7
tests/clone/nonetwork.c
+8
-0
No files found.
src/clone.c
View file @
6bb35878
...
...
@@ -259,30 +259,38 @@ cleanup:
static
int
update_head_to_branch
(
git_repository
*
repo
,
const
char
*
remote_nam
e
,
git_remote
*
remot
e
,
const
char
*
branch
,
const
char
*
reflog_message
)
{
int
retcode
;
git_buf
remote_branch_name
=
GIT_BUF_INIT
;
git_reference
*
remote_ref
=
NULL
;
git_buf
default_branch
=
GIT_BUF_INIT
;
GIT_ASSERT_ARG
(
remote
_name
);
GIT_ASSERT_ARG
(
remote
);
GIT_ASSERT_ARG
(
branch
);
if
((
retcode
=
git_buf_printf
(
&
remote_branch_name
,
GIT_REFS_REMOTES_DIR
"%s/%s"
,
remote_name
,
branch
))
<
0
)
git_remote_name
(
remote
)
,
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
),
branch
,
reflog_message
);
if
((
retcode
=
update_head_to_new_branch
(
repo
,
git_reference_target
(
remote_ref
),
branch
,
reflog_message
))
<
0
)
goto
cleanup
;
if
((
retcode
=
git_remote_default_branch
(
&
default_branch
,
remote
))
<
0
)
goto
cleanup
;
retcode
=
update_remote_head
(
repo
,
remote
,
&
default_branch
,
reflog_message
);
cleanup:
git_reference_free
(
remote_ref
);
git_buf_dispose
(
&
remote_branch_name
);
git_buf_dispose
(
&
default_branch
);
return
retcode
;
}
...
...
@@ -367,8 +375,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
int
error
;
if
(
branch
)
error
=
update_head_to_branch
(
repo
,
git_remote_name
(
remote
),
branch
,
reflog_message
);
error
=
update_head_to_branch
(
repo
,
remote
,
branch
,
reflog_message
);
/* Point HEAD to the same ref as the remote's head */
else
error
=
update_head_to_remote
(
repo
,
remote
,
reflog_message
);
...
...
tests/clone/nonetwork.c
View file @
6bb35878
...
...
@@ -158,6 +158,8 @@ void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
void
test_clone_nonetwork__can_checkout_given_branch
(
void
)
{
git_reference
*
remote_head
;
g_options
.
checkout_branch
=
"test"
;
cl_git_pass
(
git_clone
(
&
g_repo
,
cl_git_fixture_url
(
"testrepo.git"
),
"./foo"
,
&
g_options
));
...
...
@@ -167,6 +169,12 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
cl_assert_equal_s
(
git_reference_name
(
g_ref
),
"refs/heads/test"
);
cl_assert
(
git_path_exists
(
"foo/readme.txt"
));
cl_git_pass
(
git_reference_lookup
(
&
remote_head
,
g_repo
,
"refs/remotes/origin/HEAD"
));
cl_assert_equal_i
(
GIT_REFERENCE_SYMBOLIC
,
git_reference_type
(
remote_head
));
cl_assert_equal_s
(
"refs/remotes/origin/master"
,
git_reference_symbolic_target
(
remote_head
));
git_reference_free
(
remote_head
);
}
static
int
clone_cancel_fetch_transfer_progress_cb
(
...
...
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