Skip to content

Commit 2e770fe

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d31f3ad commit 2e770fe

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

builtin/fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ static void fsck_sha1_list(void)
389389
unsigned char *sha1 = entry->sha1;
390390

391391
sha1_list.entry[i] = NULL;
392-
fsck_sha1(sha1);
392+
if (fsck_sha1(sha1))
393+
errors_found |= ERROR_OBJECT;
393394
free(entry);
394395
}
395396
sha1_list.nr = 0;

t/t1450-fsck.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test_expect_success 'object with bad sha1' '
6969
git update-ref refs/heads/bogus $cmt &&
7070
test_when_finished "git update-ref -d refs/heads/bogus" &&
7171
72-
test_might_fail git fsck 2>out &&
72+
test_must_fail git fsck 2>out &&
7373
cat out &&
7474
grep "$sha.*corrupt" out
7575
'
@@ -101,7 +101,7 @@ test_expect_success 'email with embedded > is not okay' '
101101
test_when_finished "remove_object $new" &&
102102
git update-ref refs/heads/bogus "$new" &&
103103
test_when_finished "git update-ref -d refs/heads/bogus" &&
104-
git fsck 2>out &&
104+
test_must_fail git fsck 2>out &&
105105
cat out &&
106106
grep "error in commit $new" out
107107
'
@@ -113,7 +113,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
113113
test_when_finished "remove_object $new" &&
114114
git update-ref refs/heads/bogus "$new" &&
115115
test_when_finished "git update-ref -d refs/heads/bogus" &&
116-
git fsck 2>out &&
116+
test_must_fail git fsck 2>out &&
117117
cat out &&
118118
grep "error in commit $new.* - bad name" out
119119
'
@@ -125,7 +125,7 @@ test_expect_success 'missing email is reported nicely' '
125125
test_when_finished "remove_object $new" &&
126126
git update-ref refs/heads/bogus "$new" &&
127127
test_when_finished "git update-ref -d refs/heads/bogus" &&
128-
git fsck 2>out &&
128+
test_must_fail git fsck 2>out &&
129129
cat out &&
130130
grep "error in commit $new.* - missing email" out
131131
'
@@ -137,7 +137,7 @@ test_expect_success '> in name is reported' '
137137
test_when_finished "remove_object $new" &&
138138
git update-ref refs/heads/bogus "$new" &&
139139
test_when_finished "git update-ref -d refs/heads/bogus" &&
140-
git fsck 2>out &&
140+
test_must_fail git fsck 2>out &&
141141
cat out &&
142142
grep "error in commit $new" out
143143
'
@@ -151,11 +151,31 @@ test_expect_success 'integer overflow in timestamps is reported' '
151151
test_when_finished "remove_object $new" &&
152152
git update-ref refs/heads/bogus "$new" &&
153153
test_when_finished "git update-ref -d refs/heads/bogus" &&
154-
git fsck 2>out &&
154+
test_must_fail git fsck 2>out &&
155155
cat out &&
156156
grep "error in commit $new.*integer overflow" out
157157
'
158158

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+
159179
test_expect_success 'tag pointing to nonexistent' '
160180
cat >invalid-tag <<-\EOF &&
161181
object ffffffffffffffffffffffffffffffffffffffff

t/t4212-log-corrupt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test_expect_success 'setup' '
1414
'
1515

1616
test_expect_success 'fsck notices broken commit' '
17-
git fsck 2>actual &&
17+
test_must_fail git fsck 2>actual &&
1818
test_i18ngrep invalid.author actual
1919
'
2020

0 commit comments

Comments
 (0)