diff --git a/builtin/fsck.c b/builtin/fsck.c index bacc899a32..3d9ee310d2 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -778,7 +778,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) * default ones from .git/refs. We also consider the index file * in this case (ie this implies --cache). */ - if (!heads) { + if (!argc) { get_default_heads(); keep_cache_objects = 1; } diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 6b6db62c4e..509d69c90e 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -616,4 +616,15 @@ test_expect_success 'fsck $name notices bogus $name' ' test_must_fail git fsck $_z40 ' +test_expect_success 'bogus head does not fallback to all heads' ' + # set up a case that will cause a reachability complaint + echo to-be-deleted >foo && + git add foo && + blob=$(git rev-parse :foo) && + test_when_finished "git rm --cached foo" && + remove_object $blob && + test_must_fail git fsck $_z40 >out 2>&1 && + ! grep $blob out +' + test_done