From: Alex Henrie <alexhenrie24@gmail.com>
To: git@vger.kernel.org
Cc: Alex Henrie <alexhenrie24@gmail.com>
Subject: [PATCH] switch: mention the --detach option when dying due to lack of a branch
Date: Wed, 23 Feb 2022 00:31:25 -0700 [thread overview]
Message-ID: <20220223073125.640133-1-alexhenrie24@gmail.com> (raw)
Users who are accustomed to doing `git checkout <tag>` assume that
`git switch <tag>` will do the same thing. Inform them of the --detach
option so they aren't left wondering why `git switch` doesn't work but
`git checkout` does.
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
builtin/checkout.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d9b31bbb6d..10a035feed 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1398,6 +1398,10 @@ static void die_expecting_a_branch(const struct branch_info *branch_info)
struct object_id oid;
char *to_free;
+ if (advice_enabled(ADVICE_DETACHED_HEAD))
+ advise(_("The specified commit is not a local branch.\n"
+ "If you want to enter detached head mode, try again with the --detach option."));
+
if (dwim_ref(branch_info->name, strlen(branch_info->name), &oid, &to_free, 0) == 1) {
const char *ref = to_free;
--
2.35.1
next reply other threads:[~2022-02-23 7:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 7:31 Alex Henrie [this message]
2022-02-23 23:07 ` [PATCH] switch: mention the --detach option when dying due to lack of a branch Junio C Hamano
2022-02-23 23:30 ` Alex Henrie
2022-02-23 23:56 ` Ævar Arnfjörð Bjarmason
2022-02-24 6:08 ` Alex Henrie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220223073125.640133-1-alexhenrie24@gmail.com \
--to=alexhenrie24@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).