Nicolas Pitre | ac93910 | 2008-07-14 21:46:48 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rev-list should notice bad commits' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | # Note: |
| 8 | # - compression level is set to zero to make "corruptions" easier to perform |
| 9 | # - reflog is disabled to avoid extra references which would twart the test |
| 10 | |
| 11 | test_expect_success 'setup' \ |
| 12 | ' |
| 13 | git init && |
| 14 | git config core.compression 0 && |
| 15 | git config core.logallrefupdates false && |
| 16 | echo "foo" > foo && |
| 17 | git add foo && |
| 18 | git commit -m "first commit" && |
| 19 | echo "bar" > bar && |
| 20 | git add bar && |
| 21 | git commit -m "second commit" && |
| 22 | echo "baz" > baz && |
| 23 | git add baz && |
| 24 | git commit -m "third commit" && |
| 25 | echo "foo again" >> foo && |
| 26 | git add foo && |
| 27 | git commit -m "fourth commit" && |
| 28 | git repack -a -f -d |
| 29 | ' |
| 30 | |
| 31 | test_expect_success 'verify number of revisions' \ |
| 32 | ' |
| 33 | revs=$(git rev-list --all | wc -l) && |
| 34 | test $revs -eq 4 && |
| 35 | first_commit=$(git rev-parse HEAD~3) |
| 36 | ' |
| 37 | |
| 38 | test_expect_success 'corrupt second commit object' \ |
| 39 | ' |
Junio C Hamano | 7096b64 | 2012-06-12 09:49:59 -0700 | [diff] [blame] | 40 | "$PERL_PATH" -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack && |
Nicolas Pitre | ac93910 | 2008-07-14 21:46:48 -0400 | [diff] [blame] | 41 | test_must_fail git fsck --full |
| 42 | ' |
| 43 | |
| 44 | test_expect_success 'rev-list should fail' \ |
| 45 | ' |
| 46 | test_must_fail git rev-list --all > /dev/null |
| 47 | ' |
| 48 | |
| 49 | test_expect_success 'git repack _MUST_ fail' \ |
| 50 | ' |
| 51 | test_must_fail git repack -a -f -d |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'first commit is still available' \ |
| 55 | ' |
| 56 | git log $first_commit |
| 57 | ' |
| 58 | |
| 59 | test_done |
| 60 | |