aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-04-12 11:31:39 -0700
committerJunio C Hamano <gitster@pobox.com>2024-04-12 11:31:39 -0700
commit847af43a3afb39394d5fe58192f94b993ca18f9f (patch)
tree178ed69067b4dc0a824eacd0987dbfdfb8bbf2ec
parentd8800f630a55264c11693d665846c96caa5a4d1c (diff)
parentb9f2e1a684e3729b0278950cd7e930441d84c9f1 (diff)
downloadgit-847af43a3afb39394d5fe58192f94b993ca18f9f.tar.gz
Merge branch 'jc/checkout-detach-wo-tracking-report'
"git checkout/switch --detach foo", after switching to the detached HEAD state, gave the tracking information for the 'foo' branch, which was pointless. Tested-by: M Hickford <mirth.hickford@gmail.com> cf. <CAGJzqsmE9FDEBn=u3ge4LA3ha4fDbm4OWiuUbMaztwjELBd7ug@mail.gmail.com> * jc/checkout-detach-wo-tracking-report: checkout: omit "tracking" information on a detached HEAD
-rw-r--r--builtin/checkout.c3
-rwxr-xr-xt/t2020-checkout-detach.sh5
2 files changed, 6 insertions, 2 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2b6166c284..947827de1d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1035,7 +1035,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
remove_branch_state(the_repository, !opts->quiet);
strbuf_release(&msg);
if (!opts->quiet &&
- (new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
+ !opts->force_detach &&
+ (new_branch_info->path || !strcmp(new_branch_info->name, "HEAD")))
report_tracking(new_branch_info);
}
diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh
index bce284c297..8d90d02850 100755
--- a/t/t2020-checkout-detach.sh
+++ b/t/t2020-checkout-detach.sh
@@ -176,7 +176,10 @@ test_expect_success 'tracking count is accurate after orphan check' '
git config branch.child.merge refs/heads/main &&
git checkout child^ &&
git checkout child >stdout &&
- test_cmp expect stdout
+ test_cmp expect stdout &&
+
+ git checkout --detach child >stdout &&
+ test_grep ! "can be fast-forwarded\." stdout
'
test_expect_success 'no advice given for explicit detached head state' '