Skip to content

Commit 7c96471

Browse files
committed
Merge branch 'sb/checkout-explit-detach-no-advice' into maint
"git checkout --detach <branch>" used to give the same advice message as that is issued when "git checkout <tag>" (or anything that is not a branch name) is given, but asking with "--detach" is an explicit enough sign that the user knows what is going on. The advice message has been squelched in this case. * sb/checkout-explit-detach-no-advice: checkout: do not mention detach advice for explicit --detach option
2 parents 6930731 + 779b88a commit 7c96471

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
655655
update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
656656
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
657657
if (!opts->quiet) {
658-
if (old->path && advice_detached_head)
658+
if (old->path &&
659+
advice_detached_head && !opts->force_detach)
659660
detach_advice(new->name);
660661
describe_detached_head(_("HEAD is now at"), new->commit);
661662
}

t/t2020-checkout-detach.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,27 @@ test_expect_success 'tracking count is accurate after orphan check' '
163163
test_i18ncmp expect stdout
164164
'
165165

166+
test_expect_success 'no advice given for explicit detached head state' '
167+
# baseline
168+
test_config advice.detachedHead true &&
169+
git checkout child && git checkout HEAD^0 >expect.advice 2>&1 &&
170+
test_config advice.detachedHead false &&
171+
git checkout child && git checkout HEAD^0 >expect.no-advice 2>&1 &&
172+
test_unconfig advice.detachedHead &&
173+
# without configuration, the advice.* variables default to true
174+
git checkout child && git checkout HEAD^0 >actual 2>&1 &&
175+
test_cmp expect.advice actual &&
176+
177+
# with explicit --detach
178+
# no configuration
179+
test_unconfig advice.detachedHead &&
180+
git checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&
181+
test_cmp expect.no-advice actual &&
182+
183+
# explicitly decline advice
184+
test_config advice.detachedHead false &&
185+
git checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&
186+
test_cmp expect.no-advice actual
187+
'
188+
166189
test_done

0 commit comments

Comments
 (0)