summaryrefslogtreecommitdiff
path: root/t/t6011-rev-list-with-bad-commit.sh
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2008-07-15 01:46:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-07-15 06:35:32 (GMT)
commitac9391093f54370ff3f06470e24d78b536a12327 (patch)
tree256cb6bab6ae98cb5c00017885bd658c8757ace5 /t/t6011-rev-list-with-bad-commit.sh
parent25a1f374f0ff23a4d9191436226ab68f3da5e83a (diff)
downloadgit-ac9391093f54370ff3f06470e24d78b536a12327.zip
git-ac9391093f54370ff3f06470e24d78b536a12327.tar.gz
git-ac9391093f54370ff3f06470e24d78b536a12327.tar.bz2
restore legacy behavior for read_sha1_file()
Since commit 8eca0b47ff1598a6d163df9358c0e0c9bd92d4c8, it is possible for read_sha1_file() to return NULL even with existing objects when they are corrupted. Previously a corrupted object would have terminated the program immediately, effectively making read_sha1_file() return NULL only when specified object is not found. Let's restore this behavior for all users of read_sha1_file() and provide a separate function with the ability to not terminate when bad objects are encountered. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6011-rev-list-with-bad-commit.sh')
-rwxr-xr-xt/t6011-rev-list-with-bad-commit.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh
new file mode 100755
index 0000000..e51eb41
--- /dev/null
+++ b/t/t6011-rev-list-with-bad-commit.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+test_description='git rev-list should notice bad commits'
+
+. ./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
+