@matheusbsbs / matheus-bagliano / commits / f0298cf1c6
Fork 0

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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 16, 2009 at 13:52 UTC f0298cf1c6a7b5cc8b79d84a03b0ce07df2d9e6b
3 files changed +41 -2
revision.c
+1
@@ -1223,6 +1223,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1223
1224 if (!strcmp(arg, "--all")) {
1225 handle_refs(revs, flags, for_each_ref);
1226 + handle_refs(revs, flags, head_ref);
1227 continue;
1228 }
1229 if (!strcmp(arg, "--branches")) {
t/t5701-clone-local.sh
+2 -2
@@ -11,8 +11,8 @@ test_expect_success 'preparing origin repository' '
11 git clone --bare . x &&
12 test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
13 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 &&
16 mkdir dir &&
17 cp b1.bundle dir/b3
18 cp b1.bundle b4
t/t6014-rev-list-all.sh new
+38
@@ -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