Skip to content

Commit

Permalink
Fix seriously broken "git pack-refs"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jan 26, 2007
1 parent 535514f commit 1b55593
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin-pack-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions t/t3210-pack-refs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1b55593

Please sign in to comment.