Merge branch 'bp/checkout-new-branch-optim'

"git checkout -b <new> [HEAD]" to create a new branch from the
current commit and check it out ought to be a no-op in the index
and the working tree in normal cases, but there are corner cases
that do require updates to the index and the working tree.  Running
it immediately after "git clone --no-checkout" is one of these
cases that an earlier optimization kicked in incorrectly, which has
been fixed.

* bp/checkout-new-branch-optim:
  checkout: fix regression in checkout -b on intitial checkout
  checkout: add test demonstrating regression with checkout -b on initial commit
This commit is contained in:
Junio C Hamano 2019-02-05 14:26:17 -08:00
Родитель 264def5ab7 8424bfd45b
Коммит 5ad3550f02
2 изменённых файлов: 17 добавлений и 0 удалений

Просмотреть файл

@ -592,6 +592,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;
}

Просмотреть файл

@ -198,4 +198,13 @@ test_expect_success 'checkout -B to the current branch works' '
test_dirty_mergeable
'
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)" &&
git clone --no-checkout src dest &&
git -C dest checkout "$rev" -b branch &&
test_path_is_file dest/a.t
'
test_done