Skip to content

Commit

Permalink
fsck: tighten error-checks of "git fsck <head>"
Browse files Browse the repository at this point in the history
Instead of checking reachability from the refs, you can ask
fsck to check from a particular set of heads. However, the
error checking here is quite lax. In particular:

  1. It claims lookup_object() will report an error, which
     is not true. It only does a hash lookup, and the user
     has no clue that their argument was skipped.

  2. When either the name or sha1 cannot be resolved, we
     continue to exit with a successful error code, even
     though we didn't check what the user asked us to.

This patch fixes both of these cases.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Jan 17, 2017
1 parent 3e3f8bd commit c6c7b16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,11 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
if (!get_sha1(arg, sha1)) {
struct object *obj = lookup_object(sha1);

/* Error is printed by lookup_object(). */
if (!obj)
if (!obj) {
error("%s: object missing", sha1_to_hex(sha1));
errors_found |= ERROR_OBJECT;
continue;
}

obj->used = 1;
if (name_objects)
Expand All @@ -768,6 +770,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
continue;
}
error("invalid parameter: expected sha1, got '%s'", arg);
errors_found |= ERROR_OBJECT;
}

/*
Expand Down
5 changes: 5 additions & 0 deletions t/t1450-fsck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,9 @@ test_expect_success 'fsck notices dangling objects' '
)
'

test_expect_success 'fsck $name notices bogus $name' '
test_must_fail git fsck bogus &&
test_must_fail git fsck $_z40
'

test_done

0 comments on commit c6c7b16

Please sign in to comment.