Fix seriously broken "git pack-refs"
Do *NOT* try this on a repository you care about: git pack-refs --all --prune git pack-refs because while the first "pack-refs" does the right thing, the second pack-refs will totally screw you over. This is because the second one tries to pack only tags; we should also pack what are already packed -- otherwise we would lose them. [jc: with an additional test] Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Jan 25, 2007 at 16:51 UTC
1b555932cdb7f75239623573cd2ff25fa98ab4e4
2 files changed
+12
-1
builtin-pack-refs.c
+3
-1
@@ -37,7 +37,9 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
37
if ((flags & REF_ISSYMREF))
38
return 0;
39
is_tag_ref = !strncmp(path, "refs/tags/", 10);
40
- if (!cb->all && !is_tag_ref)
40
+
41
+ /* ALWAYS pack refs that were already packed or are tags */
42
+ if (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED))
43
return 0;
44
45
fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), path);
t/t3210-pack-refs.sh
+9
@@ -96,4 +96,13 @@ test_expect_success \
96
git-branch -d n/o/p &&
97
git-branch n'
98
99
+test_expect_success 'pack, prune and repack' '
100
+ git-tag foo &&
101
+ git-pack-refs --all --prune &&
102
+ git-show-ref >all-of-them &&
103
+ git-pack-refs &&
104
+ git-show-ref >again &&
105
+ diff all-of-them again
106
+'
107
+
108
test_done