checkout: do not mention detach advice for explicit --detach option
When a user asked for a detached HEAD specifically with `--detach`, we do not need to give advice on what a detached HEAD state entails as we can assume they know what they're getting into as they asked for it. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 15, 2016 at 11:40 UTC
779b88a91fb9719683bed78c81ef6ace1cedd7da
2 files changed
+25
-1
builtin/checkout.c
+2
-1
@@ -655,7 +655,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
655
update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
656
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
657
if (!opts->quiet) {
658
- if (old->path && advice_detached_head)
658
+ if (old->path &&
659
+ advice_detached_head && !opts->force_detach)
660
detach_advice(new->name);
661
describe_detached_head(_("HEAD is now at"), new->commit);
662
}
t/t2020-checkout-detach.sh
+23
@@ -163,4 +163,27 @@ test_expect_success 'tracking count is accurate after orphan check' '
163
test_i18ncmp expect stdout
164
'
165
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
+
189
test_done