fsck: tighten error-checks of "git fsck <head>"

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>

Jeff King committed Jan 16, 2017 at 16:33 UTC c6c7b16d23a4cb6af26acee865c2ade1a3822bef
2 files changed +10 -2
builtin/fsck.c
+5 -2
@@ -755,9 +755,11 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
755 if (!get_sha1(arg, sha1)) {
756 struct object *obj = lookup_object(sha1);
757
758 - /* Error is printed by lookup_object(). */
759 - if (!obj)
758 + if (!obj) {
759 + error("%s: object missing", sha1_to_hex(sha1));
760 + errors_found |= ERROR_OBJECT;
761 continue;
762 + }
763
764 obj->used = 1;
765 if (name_objects)
@@ -768,6 +770,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
770 continue;
771 }
772 error("invalid parameter: expected sha1, got '%s'", arg);
773 + errors_found |= ERROR_OBJECT;
774 }
775
776 /*
t/t1450-fsck.sh
+5
@@ -611,4 +611,9 @@ test_expect_success 'fsck notices dangling objects' '
611 )
612 '
613
614 +test_expect_success 'fsck $name notices bogus $name' '
615 + test_must_fail git fsck bogus &&
616 + test_must_fail git fsck $_z40
617 +'
618 +
619 test_done