Skip to content

Commit

Permalink
checkout: fix regression in checkout -b on intitial checkout
Browse files Browse the repository at this point in the history
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 fa655d8
(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>
  • Loading branch information
benpeart authored and gitster committed Jan 23, 2019
1 parent 91e3d7c commit 8424bfd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions builtin/checkout.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion t/t2018-checkout-branch.sh
Expand Up @@ -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)" &&
Expand Down

0 comments on commit 8424bfd

Please sign in to comment.