Skip to content

Commit 847af43

Browse files
committed
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 <[email protected]> cf. <CAGJzqsmE9FDEBn=u3ge4LA3ha4fDbm4OWiuUbMaztwjELBd7ug@mail.gmail.com> * jc/checkout-detach-wo-tracking-report: checkout: omit "tracking" information on a detached HEAD
2 parents d8800f6 + b9f2e1a commit 847af43

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
10351035
remove_branch_state(the_repository, !opts->quiet);
10361036
strbuf_release(&msg);
10371037
if (!opts->quiet &&
1038-
(new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name, "HEAD"))))
1038+
!opts->force_detach &&
1039+
(new_branch_info->path || !strcmp(new_branch_info->name, "HEAD")))
10391040
report_tracking(new_branch_info);
10401041
}
10411042

t/t2020-checkout-detach.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ test_expect_success 'tracking count is accurate after orphan check' '
176176
git config branch.child.merge refs/heads/main &&
177177
git checkout child^ &&
178178
git checkout child >stdout &&
179-
test_cmp expect stdout
179+
test_cmp expect stdout &&
180+
181+
git checkout --detach child >stdout &&
182+
test_grep ! "can be fast-forwarded\." stdout
180183
'
181184

182185
test_expect_success 'no advice given for explicit detached head state' '

0 commit comments

Comments
 (0)