git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] switch: mention the --detach option when dying due to lack of a branch

From
Alex Henrie <alexhenrie24@gmail.com>
Date
Feb 23, 2022, 23:30 UTC
Message-ID
<CAMMLpeQWjs0C4VwfpzOhZvY0Tm2YTnC74tyUeBG9bBzsNA42_w@mail.gmail.com>
In-Reply-To
<xmqqwnhlp4h1.fsf@gitster.g>
On Wed, Feb 23, 2022 at 4:07 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
>
> Alex Henrie <alexhenrie24@gmail.com> writes:
>
> > 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.
>
> An error message certainly would help over showing
>
>         fatal: a branch is expected, got tag 'abc'
>
> but I have to wonder why we shouldn't DWIM and detach the HEAD at
> the commit the user wanted to.  That would also solve the issue of
> leaving them wondering why switch is broken and checkout is not, no?
>
> If the advice for detached HEAD state is enabled, then the user will
> be reminded that they are not on any branch the usual way when the
> HEAD is detached at the named commit.  And if the advice is not
> enabled, then they will not be helped by this new advise() message
> we add here.

Before commit 7968bef06b "switch: only allow explicit detached HEAD", `git switch` did not require --detach to enter a detached HEAD state. The justification in the commit message is worth reading, but I don't have an opinion on whether or not it was a change for the better.

Show 8 quoted lines
> > +     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."));
> > +
>
> "detached HEAD" is a state, and not a mode.
>
> s/enter detached head mode/detach HEAD at the commit/ perhaps.
Sure. I'll send a v2 tonight.
-Alex
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 3 of 5 in “switch: mention the --detach option when dying due to lack of a branch”
  1. switch: mention the --detach option when dying due to lack of a branchAlex Henrie, Feb 23, 2022
  2. Junio C HamanoFeb 23, 2022
  3. Alex HenrieFeb 23, 2022
  4. Ævar Arnfjörð BjarmasonFeb 23, 2022
  5. Alex HenrieFeb 24, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.