checkout: fix regression in checkout -b on intitial checkout
authorBen Peart <benpeart@microsoft.com>
Wed, 23 Jan 2019 20:02:01 +0000 (15:02 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Jan 2019 21:22:48 +0000 (13:22 -0800)
When doing a 'checkout -b' do a full checkout including updating the working
tree when doing the initial checkout. As the new test involves an filesystem
access, do it later in the sequence to give chance to other cheaper tests to
leave early. This fixes the regression in behavior caused by fa655d8411
(checkout: optimize "git checkout -b <new_branch>", 2018-08-16).

Signed-off-by: Ben Peart <benpeart@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
t/t2018-checkout-branch.sh
index 21bac3a561dfa253d54f35f052c83e132396b598..99b873d3cd4075d59cd4133ca1de021812bc2990 100644 (file)
@@ -566,6 +566,14 @@ static int skip_merge_working_tree(const struct checkout_opts *opts,
         * Remaining variables are not checkout options but used to track state
         */
 
+        /*
+         * Do the merge if this is the initial checkout. We cannot use
+         * is_cache_unborn() here because the index hasn't been loaded yet
+         * so cache_nr and timestamp.sec are always zero.
+         */
+       if (!file_exists(get_index_file()))
+               return 0;
+
        return 1;
 }
 
index 6da2d4e68fac0483cebbf02f3d2bddfa09ad57fa..c5014ad9a63f2451f84db5076f902a0132d318c1 100755 (executable)
@@ -198,7 +198,7 @@ test_expect_success 'checkout -B to the current branch works' '
        test_dirty_mergeable
 '
 
-test_expect_failure 'checkout -b after clone --no-checkout does a checkout of HEAD' '
+test_expect_success 'checkout -b after clone --no-checkout does a checkout of HEAD' '
        git init src &&
        test_commit -C src a &&
        rev="$(git -C src rev-parse HEAD)" &&