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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 23, 2022 at 4:07 PM Junio C Hamano <gitster@xxxxxxxxx> wrote:
>
> Alex Henrie <alexhenrie24@xxxxxxxxx> 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.

> > +     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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux