Skip to content

Commit f50c440

Browse files
dschogitster
authored andcommitted
fsck: disallow demoting grave fsck errors to warnings
Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 70a4ae7 commit f50c440

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

fsck.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
#include "refs.h"
1010
#include "utf8.h"
1111

12+
#define FSCK_FATAL -1
13+
1214
#define FOREACH_MSG_ID(FUNC) \
15+
/* fatal errors */ \
16+
FUNC(NUL_IN_HEADER, FATAL) \
17+
FUNC(UNTERMINATED_HEADER, FATAL) \
1318
/* errors */ \
1419
FUNC(BAD_DATE, ERROR) \
1520
FUNC(BAD_DATE_OVERFLOW, ERROR) \
@@ -39,11 +44,9 @@
3944
FUNC(MISSING_TYPE, ERROR) \
4045
FUNC(MISSING_TYPE_ENTRY, ERROR) \
4146
FUNC(MULTIPLE_AUTHORS, ERROR) \
42-
FUNC(NUL_IN_HEADER, ERROR) \
4347
FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
4448
FUNC(TREE_NOT_SORTED, ERROR) \
4549
FUNC(UNKNOWN_TYPE, ERROR) \
46-
FUNC(UNTERMINATED_HEADER, ERROR) \
4750
FUNC(ZERO_PADDED_DATE, ERROR) \
4851
/* warnings */ \
4952
FUNC(BAD_FILEMODE, WARN) \
@@ -149,6 +152,9 @@ void fsck_set_msg_type(struct fsck_options *options,
149152
die("Unhandled message id: %s", msg_id);
150153
type = parse_msg_type(msg_type);
151154

155+
if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
156+
die("Cannot demote %s to %s", msg_id, msg_type);
157+
152158
if (!options->msg_type) {
153159
int i;
154160
int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
@@ -216,6 +222,9 @@ static int report(struct fsck_options *options, struct object *object,
216222
struct strbuf sb = STRBUF_INIT;
217223
int msg_type = fsck_msg_type(id, options), result;
218224

225+
if (msg_type == FSCK_FATAL)
226+
msg_type = FSCK_ERROR;
227+
219228
append_msg_id(&sb, msg_id_info[id].id_string);
220229

221230
va_start(ap, fmt);

t/t5504-fetch-receive-strict.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
136136
grep "missingEmail" act
137137
'
138138

139+
test_expect_success \
140+
'receive.fsck.unterminatedHeader=warn triggers error' '
141+
rm -rf dst &&
142+
git init dst &&
143+
git --git-dir=dst/.git config receive.fsckobjects true &&
144+
git --git-dir=dst/.git config \
145+
receive.fsck.unterminatedheader warn &&
146+
test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
147+
grep "Cannot demote unterminatedheader" act
148+
'
149+
139150
test_done

0 commit comments

Comments
 (0)