fsck: do not fallback "git fsck <bogus>" to "git fsck"
Since fsck tries to continue as much as it can after seeing an error, we still do the reachability check even if some heads we were given on the command-line are bogus. But if _none_ of the heads is is valid, we fallback to checking all refs and the index, which is not what the user asked for at all. Instead of checking "heads", the number of successful heads we got, check "argc" (which we know only has non-options in it, because parse_options removed the others). 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:34 UTC
c3271a0e4715eb9c3f03dde4fdda23f50cc176c3
2 files changed
+12
-1
builtin/fsck.c
+1
-1
@@ -778,7 +778,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
778
* default ones from .git/refs. We also consider the index file
779
* in this case (ie this implies --cache).
780
*/
781
- if (!heads) {
781
+ if (!argc) {
782
get_default_heads();
783
keep_cache_objects = 1;
784
}
t/t1450-fsck.sh
+11
@@ -616,4 +616,15 @@ test_expect_success 'fsck $name notices bogus $name' '
616
test_must_fail git fsck $_z40
617
'
618
619
+test_expect_success 'bogus head does not fallback to all heads' '
620
+ # set up a case that will cause a reachability complaint
621
+ echo to-be-deleted >foo &&
622
+ git add foo &&
623
+ blob=$(git rev-parse :foo) &&
624
+ test_when_finished "git rm --cached foo" &&
625
+ remove_object $blob &&
626
+ test_must_fail git fsck $_z40 >out 2>&1 &&
627
+ ! grep $blob out
628
+'
629
+
630
test_done