diff options
-rw-r--r-- | Documentation/git.txt | 19 | ||||
-rw-r--r-- | refs.c | 2 | ||||
-rwxr-xr-x | t/t5312-prune-corruption.sh | 10 | ||||
-rwxr-xr-x | t/t5516-fetch-push.sh | 7 |
4 files changed, 23 insertions, 15 deletions
diff --git a/Documentation/git.txt b/Documentation/git.txt index abace9eac2..d63c65e67d 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -867,15 +867,16 @@ for full details. end user, to be recorded in the body of the reflog. `GIT_REF_PARANOIA`:: - If set to `1`, include broken or badly named refs when iterating - over lists of refs. In a normal, non-corrupted repository, this - does nothing. However, enabling it may help git to detect and - abort some operations in the presence of broken refs. Git sets - this variable automatically when performing destructive - operations like linkgit:git-prune[1]. You should not need to set - it yourself unless you want to be paranoid about making sure - an operation has touched every ref (e.g., because you are - cloning a repository to make a backup). + If set to `0`, ignore broken or badly named refs when iterating + over lists of refs. Normally Git will try to include any such + refs, which may cause some operations to fail. This is usually + preferable, as potentially destructive operations (e.g., + linkgit:git-prune[1]) are better off aborting rather than + ignoring broken refs (and thus considering the history they + point to as not worth saving). The default value is `1` (i.e., + be paranoid about detecting and aborting all operations). You + should not normally need to set this to `0`, but it may be + useful when trying to salvage data from a corrupted repository. `GIT_ALLOW_PROTOCOL`:: If set to a colon-separated list of protocols, behave as if @@ -1420,7 +1420,7 @@ struct ref_iterator *refs_ref_iterator_begin( if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) { if (ref_paranoia < 0) - ref_paranoia = git_env_bool("GIT_REF_PARANOIA", 0); + ref_paranoia = git_env_bool("GIT_REF_PARANOIA", 1); if (ref_paranoia) { flags |= DO_FOR_EACH_INCLUDE_BROKEN; flags |= DO_FOR_EACH_OMIT_DANGLING_SYMREFS; diff --git a/t/t5312-prune-corruption.sh b/t/t5312-prune-corruption.sh index d8ec5a7462..ea889c088a 100755 --- a/t/t5312-prune-corruption.sh +++ b/t/t5312-prune-corruption.sh @@ -49,11 +49,17 @@ test_expect_success 'put bogus object into pack' ' git cat-file -e $bogus ' -test_expect_success 'non-destructive repack ignores bogus name' ' +test_expect_success 'non-destructive repack bails on bogus ref' ' create_bogus_ref && - git repack -adk + test_must_fail git repack -adk ' +test_expect_success 'GIT_REF_PARANOIA=0 overrides safety' ' + create_bogus_ref && + GIT_REF_PARANOIA=0 git repack -adk +' + + test_expect_success 'destructive repack keeps packed object' ' create_bogus_ref && test_must_fail git repack -Ad --unpack-unreachable=now && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index b13553ecf4..8212ca56dc 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -707,20 +707,21 @@ test_expect_success 'pushing valid refs triggers post-receive and post-update ho test_expect_success 'deleting dangling ref triggers hooks with correct args' ' mk_test_with_hooks testrepo heads/branch && + orig=$(git -C testrepo rev-parse refs/heads/branch) && rm -f testrepo/.git/objects/??/* && git push testrepo :refs/heads/branch && ( cd testrepo/.git && cat >pre-receive.expect <<-EOF && - $ZERO_OID $ZERO_OID refs/heads/branch + $orig $ZERO_OID refs/heads/branch EOF cat >update.expect <<-EOF && - refs/heads/branch $ZERO_OID $ZERO_OID + refs/heads/branch $orig $ZERO_OID EOF cat >post-receive.expect <<-EOF && - $ZERO_OID $ZERO_OID refs/heads/branch + $orig $ZERO_OID refs/heads/branch EOF cat >post-update.expect <<-EOF && |