reachable.c: add HEAD to reachability starting commits
HEAD is not explicitly used as a starting commit for calculating reachability, so if it's detached and reflogs are disabled it may be pruned. Add tests which demonstrate it. Test 'prune: prune former HEAD after checking out branch' also reverts changes to repository. Signed-off-by: Max Kirillov <max@max630.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Max Kirillov committed
Sep 3, 2014 at 19:14 UTC
c40fdd01dd120c8c63da5e830ccdeb1518434bd6
2 files changed
+25
reachable.c
+3
@@ -229,6 +229,9 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
229
/* Add all external refs */
230
for_each_ref(add_one_ref, revs);
231
232
+ /* detached HEAD is not included in the list above */
233
+ head_ref(add_one_ref, revs);
234
+
235
/* Add all reflog info */
236
if (mark_reflog)
237
for_each_reflog(add_one_reflog, revs);
t/t5304-prune.sh
+22
@@ -104,6 +104,28 @@ test_expect_success 'prune: prune unreachable heads' '
104
105
'
106
107
+test_expect_success 'prune: do not prune detached HEAD with no reflog' '
108
+
109
+ git checkout --detach --quiet &&
110
+ git commit --allow-empty -m "detached commit" &&
111
+ # verify that there is no reflogs
112
+ # (should be removed and disabled by previous test)
113
+ test ! -e .git/logs &&
114
+ git prune -n >prune_actual &&
115
+ : >prune_expected &&
116
+ test_cmp prune_actual prune_expected
117
+
118
+'
119
+
120
+test_expect_success 'prune: prune former HEAD after checking out branch' '
121
+
122
+ head_sha1=$(git rev-parse HEAD) &&
123
+ git checkout --quiet master &&
124
+ git prune -v >prune_actual &&
125
+ grep "$head_sha1" prune_actual
126
+
127
+'
128
+
129
test_expect_success 'prune: do not prune heads listed as an argument' '
130
131
: > file2 &&