From: Linus Torvalds Date: Fri, 26 Jan 2007 00:51:21 +0000 (-0800) Subject: Fix seriously broken "git pack-refs" X-Git-Tag: v1.5.0-rc3~59 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1b555932cdb7f75239623573cd2ff25fa98ab4e4;p=git.git 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 --- diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c index 6de7128b9..3de9b3eef 100644 --- a/builtin-pack-refs.c +++ b/builtin-pack-refs.c @@ -37,7 +37,9 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, if ((flags & REF_ISSYMREF)) return 0; is_tag_ref = !strncmp(path, "refs/tags/", 10); - if (!cb->all && !is_tag_ref) + + /* ALWAYS pack refs that were already packed or are tags */ + if (!cb->all && !is_tag_ref && !(flags & REF_ISPACKED)) return 0; fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), path); diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 16bdae4f2..f0c7e22b3 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -96,4 +96,13 @@ test_expect_success \ git-branch -d n/o/p && git-branch n' +test_expect_success 'pack, prune and repack' ' + git-tag foo && + git-pack-refs --all --prune && + git-show-ref >all-of-them && + git-pack-refs && + git-show-ref >again && + diff all-of-them again +' + test_done