Skip to content

Commit ff4056b

Browse files
peffgitster
authored andcommitted
prune: turn on ref_paranoia flag
Prune should know about broken objects at the tips of refs, so that we can feed them to our traversal rather than ignoring them. It's better for us to abort the operation on the broken object than it is to start deleting objects with an incomplete view of the reachability namespace. Note that for missing objects, aborting is the best we can do. For a badly-named ref, we technically could use its sha1 as a reachability tip. However, the iteration code just feeds us a null sha1, so there would be a reasonable amount of code involved to pass down our wishes. It's not really worth trying to do better, because this is a case that should happen extremely rarely, and the message we provide: fatal: unable to parse object: refs/heads/bogus:name is probably enough to point the user in the right direction. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49672f2 commit ff4056b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

builtin/prune.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
115115
expire = ULONG_MAX;
116116
save_commit_buffer = 0;
117117
check_replace_refs = 0;
118+
ref_paranoia = 1;
118119
init_revisions(&revs, prefix);
119120

120121
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);

t/t5312-prune-corruption.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test_expect_success 'create history reachable only from a bogus-named ref' '
2525
git reset --hard HEAD^
2626
'
2727

28-
test_expect_failure 'pruning does not drop bogus object' '
28+
test_expect_success 'pruning does not drop bogus object' '
2929
test_when_finished "git hash-object -w -t commit saved" &&
3030
test_might_fail git prune --expire=now &&
3131
verbose git cat-file -e $bogus
@@ -72,7 +72,7 @@ test_expect_success 'create history with missing tip commit' '
7272
test_must_fail git cat-file -e $missing
7373
'
7474

75-
test_expect_failure 'pruning with a corrupted tip does not drop history' '
75+
test_expect_success 'pruning with a corrupted tip does not drop history' '
7676
test_when_finished "git hash-object -w -t commit saved" &&
7777
test_might_fail git prune --expire=now &&
7878
verbose git cat-file -e $recoverable

0 commit comments

Comments
 (0)