Skip to content

Commit f0298cf

Browse files
dschogitster
authored andcommitted
revision walker: include a detached HEAD in --all
When HEAD is detached, --all should list it, too, logically, as a detached HEAD is by definition a temporary, unnamed branch. It is especially necessary to list it when garbage collecting, as the detached HEAD would be trashed. Noticed by Thomas Rast. Note that this affects creating bundles with --all; I contend that it is a good change to add the HEAD, so that cloning from such a bundle will give you a current branch. However, I had to fix t5701 as it assumed that --all does not imply HEAD. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bf474e2 commit f0298cf

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

revision.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
12231223

12241224
if (!strcmp(arg, "--all")) {
12251225
handle_refs(revs, flags, for_each_ref);
1226+
handle_refs(revs, flags, head_ref);
12261227
continue;
12271228
}
12281229
if (!strcmp(arg, "--branches")) {

t/t5701-clone-local.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ test_expect_success 'preparing origin repository' '
1111
git clone --bare . x &&
1212
test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
1313
test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true
14-
git bundle create b1.bundle --all HEAD &&
15-
git bundle create b2.bundle --all &&
14+
git bundle create b1.bundle master HEAD &&
15+
git bundle create b2.bundle master &&
1616
mkdir dir &&
1717
cp b1.bundle dir/b3
1818
cp b1.bundle b4

t/t6014-rev-list-all.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
test_description='--all includes detached HEADs'
4+
5+
. ./test-lib.sh
6+
7+
8+
commit () {
9+
test_tick &&
10+
echo $1 > foo &&
11+
git add foo &&
12+
git commit -m "$1"
13+
}
14+
15+
test_expect_success 'setup' '
16+
17+
commit one &&
18+
commit two &&
19+
git checkout HEAD^ &&
20+
commit detached
21+
22+
'
23+
24+
test_expect_success 'rev-list --all lists detached HEAD' '
25+
26+
test 3 = $(git rev-list --all | wc -l)
27+
28+
'
29+
30+
test_expect_success 'repack does not lose detached HEAD' '
31+
32+
git gc &&
33+
git prune --expire=now &&
34+
git show HEAD
35+
36+
'
37+
38+
test_done

0 commit comments

Comments
 (0)