From: Ben Peart The optimized `checkout -b` doesn’t typically create/update the index and working directory. Add a new test to detect the case when the call to `checkout -b` is the first call after doing a `clone --no-checkout` and no index exists. In this specific case, well now make the call to merge_working_tree() which will create the index and update the working directory. Also simplify and update the test cases based on the feedback provided by Szeder and Junio. A shout out to Johannes who diagnosed, fixed and patched a bug that was preventing me from running the git test suite in the master branch. Base Ref: master Web-Diff: https://github.com/benpeart/git/commit/55dd8602f5 Checkout: git fetch https://github.com/benpeart/git initial-checkout-v2 && git checkout 55dd8602f5 ### Interdiff (v1..v2): diff --git a/builtin/checkout.c b/builtin/checkout.c index af6b5c8336..9c6e94319e 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -517,12 +517,6 @@ static int skip_merge_working_tree(const struct checkout_opts *opts, if (core_apply_sparse_checkout && !checkout_optimize_new_branch) return 0; - /* - * We must do the merge if this is the initial checkout - */ - if (is_cache_unborn()) - return 0; - /* * We must do the merge if we are actually moving to a new commit. */ @@ -598,6 +592,13 @@ 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 + * + */ + if (!file_exists(get_index_file())) + return 0; + return 1; } diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index c438889b0c..c5014ad9a6 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -200,13 +200,11 @@ test_expect_success 'checkout -B to the current branch works' ' test_expect_success 'checkout -b after clone --no-checkout does a checkout of HEAD' ' git init src && - echo hi > src/a && - git -C src add . && - git -C src commit -m "initial commit" && + 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 -f dest/a + test_path_is_file dest/a.t ' test_done ### Patches Ben Peart (2): checkout: add test to demonstrate regression with checkout -b on initial commit checkout: fix regression in checkout -b on intitial checkout builtin/checkout.c | 7 +++++++ t/t2018-checkout-branch.sh | 9 +++++++++ 2 files changed, 16 insertions(+) base-commit: 77556354bb7ac50450e3b28999e3576969869068 -- 2.19.1.gvfs.1.16.g9d1374d