]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t5318-commit-graph.sh
commit: detect commits that exist in commit-graph but not in the ODB
[thirdparty/git.git] / t / t5318-commit-graph.sh
index 087e6ac3b84830f34f1fdc1093cad1fc2b9807aa..2c62b91ef96ba620e74d446d2c1f054da28ee866 100755 (executable)
@@ -836,4 +836,31 @@ test_expect_success 'stale commit cannot be parsed when given directly' '
        )
 '
 
+test_expect_success 'stale commit cannot be parsed when traversing graph' '
+       test_when_finished "rm -rf repo" &&
+       git init repo &&
+       (
+               cd repo &&
+
+               test_commit A &&
+               test_commit B &&
+               test_commit C &&
+               git commit-graph write --reachable &&
+
+               # Corrupt the repository by deleting the intermediate commit
+               # object. Commands should notice that this object is absent and
+               # thus that the repository is corrupt even if the commit graph
+               # exists.
+               oid=$(git rev-parse B) &&
+               rm .git/objects/"$(test_oid_to_path "$oid")" &&
+
+               # Again, we should be able to parse the commit when not
+               # being paranoid about commit graph staleness...
+               GIT_COMMIT_GRAPH_PARANOIA=false git rev-parse HEAD~2 &&
+               # ... but fail when we are paranoid.
+               test_must_fail git rev-parse HEAD~2 2>error &&
+               grep "error: commit $oid exists in commit-graph but not in the object database" error
+       )
+'
+
 test_done