git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] switch: mention the --detach option when dying due to lack of a branch
@ 2022-02-23  7:31 Alex Henrie
  2022-02-23 23:07 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Henrie @ 2022-02-23  7:31 UTC (permalink / raw)
  To: git; +Cc: Alex Henrie

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-24  6:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-23  7:31 [PATCH] switch: mention the --detach option when dying due to lack of a branch Alex Henrie
2022-02-23 23:07 ` 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

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).