fsck: tighten error-checks of "git fsck <head>"
authorJeff King <peff@peff.net>
Mon, 16 Jan 2017 21:33:29 +0000 (16:33 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 22:24:33 +0000 (14:24 -0800)
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>
builtin/fsck.c
t/t1450-fsck.sh
index 75e836e2fd544207f47ab59786fa9bf7731e3f06..bacc899a32ef0e8a2b21d6f99ca35ebae660a36d 100644 (file)
@@ -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)
@@ -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;
        }
 
        /*
index 4d1c3ba664c43d3b6bc315fdf0e96e45e4d991dc..6b6db62c4e45c68ff38e41a5b135fb4fe9b84d2c 100755 (executable)
@@ -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