Skip to content

Commit

Permalink
fsck: disallow demoting grave fsck errors to warnings
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jun 23, 2015
1 parent 70a4ae7 commit f50c440
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#include "refs.h"
#include "utf8.h"

#define FSCK_FATAL -1

#define FOREACH_MSG_ID(FUNC) \
/* fatal errors */ \
FUNC(NUL_IN_HEADER, FATAL) \
FUNC(UNTERMINATED_HEADER, FATAL) \
/* errors */ \
FUNC(BAD_DATE, ERROR) \
FUNC(BAD_DATE_OVERFLOW, ERROR) \
Expand Down Expand Up @@ -39,11 +44,9 @@
FUNC(MISSING_TYPE, ERROR) \
FUNC(MISSING_TYPE_ENTRY, ERROR) \
FUNC(MULTIPLE_AUTHORS, ERROR) \
FUNC(NUL_IN_HEADER, ERROR) \
FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
FUNC(TREE_NOT_SORTED, ERROR) \
FUNC(UNKNOWN_TYPE, ERROR) \
FUNC(UNTERMINATED_HEADER, ERROR) \
FUNC(ZERO_PADDED_DATE, ERROR) \
/* warnings */ \
FUNC(BAD_FILEMODE, WARN) \
Expand Down Expand Up @@ -149,6 +152,9 @@ void fsck_set_msg_type(struct fsck_options *options,
die("Unhandled message id: %s", msg_id);
type = parse_msg_type(msg_type);

if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
die("Cannot demote %s to %s", msg_id, msg_type);

if (!options->msg_type) {
int i;
int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
Expand Down Expand Up @@ -216,6 +222,9 @@ static int report(struct fsck_options *options, struct object *object,
struct strbuf sb = STRBUF_INIT;
int msg_type = fsck_msg_type(id, options), result;

if (msg_type == FSCK_FATAL)
msg_type = FSCK_ERROR;

append_msg_id(&sb, msg_id_info[id].id_string);

va_start(ap, fmt);
Expand Down
11 changes: 11 additions & 0 deletions t/t5504-fetch-receive-strict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
grep "missingEmail" act
'

test_expect_success \
'receive.fsck.unterminatedHeader=warn triggers error' '
rm -rf dst &&
git init dst &&
git --git-dir=dst/.git config receive.fsckobjects true &&
git --git-dir=dst/.git config \
receive.fsck.unterminatedheader warn &&
test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
grep "Cannot demote unterminatedheader" act
'

test_done

0 comments on commit f50c440

Please sign in to comment.