#!/bin/sh global test_description := ''git rev-list should notice bad commits'' source ./test-lib.sh # Note: # - compression level is set to zero to make "corruptions" easier to perform # - reflog is disabled to avoid extra references which would twart the test test_expect_success 'setup' \ ' git init && git config core.compression 0 && git config core.logallrefupdates false && echo "foo" > foo && git add foo && git commit -m "first commit" && echo "bar" > bar && git add bar && git commit -m "second commit" && echo "baz" > baz && git add baz && git commit -m "third commit" && echo "foo again" >> foo && git add foo && git commit -m "fourth commit" && git repack -a -f -d ' test_expect_success 'verify number of revisions' \ ' revs=$(git rev-list --all | wc -l) && test $revs -eq 4 && first_commit=$(git rev-parse HEAD~3) ' test_expect_success 'corrupt second commit object' \ ' perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack && test_must_fail git fsck --full ' test_expect_success 'rev-list should fail' \ ' test_must_fail git rev-list --all > /dev/null ' test_expect_success 'git repack _MUST_ fail' \ ' test_must_fail git repack -a -f -d ' test_expect_success 'first commit is still available' \ ' git log $first_commit ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git rev-list should notice bad commits">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <" git init &&\n"> <" git config core.compression 0 &&\n"> <" git config core.logallrefupdates false &&\n"> <" echo \"foo\" > foo &&\n"> <" git add foo &&\n"> <" git commit -m \"first commit\" &&\n"> <" echo \"bar\" > bar &&\n"> <" git add bar &&\n"> <" git commit -m \"second commit\" &&\n"> <" echo \"baz\" > baz &&\n"> <" git add baz &&\n"> <" git commit -m \"third commit\" &&\n"> <" echo \"foo again\" >> foo &&\n"> <" git add foo &&\n"> <" git commit -m \"fourth commit\" &&\n"> <" git repack -a -f -d\n"> <" "> ) } ) (C {(test_expect_success)} {(SQ <"verify number of revisions">)} { (SQ <"\n"> <" revs=$(git rev-list --all | wc -l) &&\n"> <" test $revs -eq 4 &&\n"> <" first_commit=$(git rev-parse HEAD~3)\n"> <" "> ) } ) (C {(test_expect_success)} {(SQ <"corrupt second commit object">)} { (SQ <"\n"> <" perl -i.bak -pe \"s/second commit/socond commit/\" .git/objects/pack/*.pack &&\n"> <" test_must_fail git fsck --full\n"> <" "> ) } ) (C {(test_expect_success)} {(SQ <"rev-list should fail">)} {(SQ <"\n"> <" test_must_fail git rev-list --all > /dev/null\n"> <" ">)} ) (C {(test_expect_success)} {(SQ <"git repack _MUST_ fail">)} {(SQ <"\n"> <" test_must_fail git repack -a -f -d\n"> <" ">)} ) (C {(test_expect_success)} {(SQ <"first commit is still available">)} {(SQ <"\n"> <" git log $first_commit\n"> <" ">)} ) (C {(test_done)}) ] )