]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/rev-list-verify-objects-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Sep 2022 18:38:24 +0000 (11:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Sep 2022 18:38:24 +0000 (11:38 -0700)
"git rev-list --verify-objects" ought to inspect the contents of
objects and notice corrupted ones, but it didn't when the commit
graph is in use, which has been corrected.

* jk/rev-list-verify-objects-fix:
  rev-list: disable commit graph with --verify-objects
  lookup_commit_in_graph(): use prepare_commit_graph() to check for graph

1  2 
commit-graph.c
revision.c
t/t1450-fsck.sh

diff --cc commit-graph.c
Simple merge
diff --cc revision.c
Simple merge
diff --cc t/t1450-fsck.sh
index 6410eff4e0a6e52a7ad5078b455632e3aa383866,f9a1bc5de763beb56681434de1e16bbaadc08111..ace4556788de761e225567787bc34ac4e6dc18bf
@@@ -507,26 -507,34 +507,54 @@@ test_expect_success 'rev-list --verify-
        test_i18ngrep -q "error: hash mismatch $(dirname $new)$(test_oid ff_2)" out
  '
  
 +# An actual bit corruption is more likely than swapped commits, but
 +# this provides an easy way to have commits which don't match their purported
 +# hashes, but which aren't so broken we can't read them at all.
 +test_expect_success 'rev-list --verify-objects notices swapped commits' '
 +      git init swapped-commits &&
 +      (
 +              cd swapped-commits &&
 +              test_commit one &&
 +              test_commit two &&
 +              one_oid=$(git rev-parse HEAD) &&
 +              two_oid=$(git rev-parse HEAD^) &&
 +              one=.git/objects/$(test_oid_to_path $one_oid) &&
 +              two=.git/objects/$(test_oid_to_path $two_oid) &&
 +              mv $one tmp &&
 +              mv $two $one &&
 +              mv tmp $two &&
 +              test_must_fail git rev-list --verify-objects HEAD
 +      )
 +'
 +
+ test_expect_success 'set up repository with commit-graph' '
+       git init corrupt-graph &&
+       (
+               cd corrupt-graph &&
+               test_commit one &&
+               test_commit two &&
+               git commit-graph write --reachable
+       )
+ '
+ corrupt_graph_obj () {
+       oid=$(git -C corrupt-graph rev-parse "$1") &&
+       obj=corrupt-graph/.git/objects/$(test_oid_to_path $oid) &&
+       test_when_finished 'mv backup $obj' &&
+       mv $obj backup &&
+       echo garbage >$obj
+ }
+ test_expect_success 'rev-list --verify-objects with commit graph (tip)' '
+       corrupt_graph_obj HEAD &&
+       test_must_fail git -C corrupt-graph rev-list --verify-objects HEAD
+ '
+ test_expect_success 'rev-list --verify-objects with commit graph (parent)' '
+       corrupt_graph_obj HEAD^ &&
+       test_must_fail git -C corrupt-graph rev-list --verify-objects HEAD
+ '
  test_expect_success 'force fsck to ignore double author' '
        git cat-file commit HEAD >basis &&
        sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&