checkout: fix regression in checkout -b on intitial checkout
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>
Ben Peart committed
Jan 23, 2019 at 15:02 UTC
8424bfd45b291a56594f0289dc6af22e900a1d88
2 files changed
+9
-1
builtin/checkout.c
+8
@@ -566,6 +566,14 @@ static int skip_merge_working_tree(const struct checkout_opts *opts,
566
* Remaining variables are not checkout options but used to track state
567
*/
568
569
+ /*
570
+ * Do the merge if this is the initial checkout. We cannot use
571
+ * is_cache_unborn() here because the index hasn't been loaded yet
572
+ * so cache_nr and timestamp.sec are always zero.
573
+ */
574
+ if (!file_exists(get_index_file()))
575
+ return 0;
576
+
577
return 1;
578
}
579
t/t2018-checkout-branch.sh
+1
-1
@@ -198,7 +198,7 @@ test_expect_success 'checkout -B to the current branch works' '
198
test_dirty_mergeable
199
'
200
201
-test_expect_failure 'checkout -b after clone --no-checkout does a checkout of HEAD' '
201
+test_expect_success 'checkout -b after clone --no-checkout does a checkout of HEAD' '
202
git init src &&
203
test_commit -C src a &&
204
rev="$(git -C src rev-parse HEAD)" &&