fsck: exit with non-zero status upon error from fsck_obj()
Upon finding a corrupt loose object, we forgot to note the error to signal it with the exit status of the entire process. [jc: adjusted t1450 and added another test] Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 29, 2014 at 16:31 UTC
2e770fe47ef9c0b20bc687e37f3eb50f1bf919d0
3 files changed
+29
-8
builtin/fsck.c
+2
-1
@@ -389,7 +389,8 @@ static void fsck_sha1_list(void)
389
unsigned char *sha1 = entry->sha1;
390
391
sha1_list.entry[i] = NULL;
392
- fsck_sha1(sha1);
392
+ if (fsck_sha1(sha1))
393
+ errors_found |= ERROR_OBJECT;
394
free(entry);
395
}
396
sha1_list.nr = 0;
t/t1450-fsck.sh
+26
-6
@@ -69,7 +69,7 @@ test_expect_success 'object with bad sha1' '
69
git update-ref refs/heads/bogus $cmt &&
70
test_when_finished "git update-ref -d refs/heads/bogus" &&
71
72
- test_might_fail git fsck 2>out &&
72
+ test_must_fail git fsck 2>out &&
73
cat out &&
74
grep "$sha.*corrupt" out
75
'
@@ -101,7 +101,7 @@ test_expect_success 'email with embedded > is not okay' '
101
test_when_finished "remove_object $new" &&
102
git update-ref refs/heads/bogus "$new" &&
103
test_when_finished "git update-ref -d refs/heads/bogus" &&
104
- git fsck 2>out &&
104
+ test_must_fail git fsck 2>out &&
105
cat out &&
106
grep "error in commit $new" out
107
'
@@ -113,7 +113,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
113
test_when_finished "remove_object $new" &&
114
git update-ref refs/heads/bogus "$new" &&
115
test_when_finished "git update-ref -d refs/heads/bogus" &&
116
- git fsck 2>out &&
116
+ test_must_fail git fsck 2>out &&
117
cat out &&
118
grep "error in commit $new.* - bad name" out
119
'
@@ -125,7 +125,7 @@ test_expect_success 'missing email is reported nicely' '
125
test_when_finished "remove_object $new" &&
126
git update-ref refs/heads/bogus "$new" &&
127
test_when_finished "git update-ref -d refs/heads/bogus" &&
128
- git fsck 2>out &&
128
+ test_must_fail git fsck 2>out &&
129
cat out &&
130
grep "error in commit $new.* - missing email" out
131
'
@@ -137,7 +137,7 @@ test_expect_success '> in name is reported' '
137
test_when_finished "remove_object $new" &&
138
git update-ref refs/heads/bogus "$new" &&
139
test_when_finished "git update-ref -d refs/heads/bogus" &&
140
- git fsck 2>out &&
140
+ test_must_fail git fsck 2>out &&
141
cat out &&
142
grep "error in commit $new" out
143
'
@@ -151,11 +151,31 @@ test_expect_success 'integer overflow in timestamps is reported' '
151
test_when_finished "remove_object $new" &&
152
git update-ref refs/heads/bogus "$new" &&
153
test_when_finished "git update-ref -d refs/heads/bogus" &&
154
- git fsck 2>out &&
154
+ test_must_fail git fsck 2>out &&
155
cat out &&
156
grep "error in commit $new.*integer overflow" out
157
'
158
159
+test_expect_success 'malformatted tree object' '
160
+ test_when_finished "git update-ref -d refs/tags/wrong" &&
161
+ test_when_finished "remove_object \$T" &&
162
+ T=$(
163
+ GIT_INDEX_FILE=test-index &&
164
+ export GIT_INDEX_FILE &&
165
+ rm -f test-index &&
166
+ >x &&
167
+ git add x &&
168
+ T=$(git write-tree) &&
169
+ (
170
+ git cat-file tree $T &&
171
+ git cat-file tree $T
172
+ ) |
173
+ git hash-object -w -t tree --stdin
174
+ ) &&
175
+ test_must_fail git fsck 2>out &&
176
+ grep "error in tree .*contains duplicate file entries" out
177
+'
178
+
179
test_expect_success 'tag pointing to nonexistent' '
180
cat >invalid-tag <<-\EOF &&
181
object ffffffffffffffffffffffffffffffffffffffff
t/t4212-log-corrupt.sh
+1
-1
@@ -14,7 +14,7 @@ test_expect_success 'setup' '
14
'
15
16
test_expect_success 'fsck notices broken commit' '
17
- git fsck 2>actual &&
17
+ test_must_fail git fsck 2>actual &&
18
test_i18ngrep invalid.author actual
19
'
20