Skip to content

Commit 4ac01b0

Browse files
committed
Merge branch 'nd/clone-single-fix' into maint
"git clone --single-branch" to clone a single branch did not limit the cloning to the specified branch. * nd/clone-single-fix: clone: fix ref selection in --single-branch --branch=xxx
2 parents c8382c1 + 0ec4b16 commit 4ac01b0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

builtin/clone.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,11 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
433433

434434
if (!option_branch)
435435
remote_head = guess_remote_head(head, refs, 0);
436-
else
437-
remote_head = find_remote_branch(refs, option_branch);
436+
else {
437+
local_refs = NULL;
438+
tail = &local_refs;
439+
remote_head = copy_ref(find_remote_branch(refs, option_branch));
440+
}
438441

439442
if (!remote_head && option_branch)
440443
warning(_("Could not find remote branch %s to clone."),

t/t5500-fetch-pack.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ test_expect_success 'single branch object count' '
125125
test_cmp expected count.singlebranch
126126
'
127127

128+
test_expect_success 'single given branch clone' '
129+
git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
130+
test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
131+
'
132+
128133
test_expect_success 'clone shallow' '
129134
git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
130135
'
@@ -276,7 +281,7 @@ test_expect_success 'clone shallow with --branch' '
276281
'
277282

278283
test_expect_success 'clone shallow object count' '
279-
echo "in-pack: 12" > count3.expected &&
284+
echo "in-pack: 6" > count3.expected &&
280285
GIT_DIR=shallow3/.git git count-objects -v |
281286
grep "^in-pack" > count3.actual &&
282287
test_cmp count3.expected count3.actual

0 commit comments

Comments
 (0)