From 91e3d7ca9b0194575c1fdbb82b74bef4eb8357a1 Mon Sep 17 00:00:00 2001 From: Ben Peart Date: Wed, 23 Jan 2019 15:02:00 -0500 Subject: checkout: add test demonstrating regression with checkout -b on initial commit Commit fa655d8411 (checkout: optimize "git checkout -b ", 2018-08-16) introduced an unintentional change in behavior for 'checkout -b' after doing 'clone --no-checkout'. Add a test to demonstrate the changed behavior to be used in a later patch to verify the fix. Signed-off-by: Ben Peart Signed-off-by: Junio C Hamano diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index 2131fb2..6da2d4e 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -198,4 +198,13 @@ 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' ' + 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 -- cgit v0.10.2-6-g49f6 From 8424bfd45b291a56594f0289dc6af22e900a1d88 Mon Sep 17 00:00:00 2001 From: Ben Peart Date: Wed, 23 Jan 2019 15:02:01 -0500 Subject: 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 ", 2018-08-16). Signed-off-by: Ben Peart Signed-off-by: Junio C Hamano diff --git a/builtin/checkout.c b/builtin/checkout.c index 21bac3a..99b873d 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -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; } diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index 6da2d4e..c5014ad 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -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)" && -- cgit v0.10.2-6-g49f6