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

Re: [PATCH RESEND 2/2] status: improve info for detached HEAD after clone

From
RERoy E <royeldar0@gmail.com>
Date
Mar 10, 2023, 16:25 UTC
Message-ID
<CAOfFamk5wWFuUgn4uEo0JV0siLzH=ybDB_Yr-9oL3OM4taozuA@mail.gmail.com>
In-Reply-To
<xmqqsfefrn4q.fsf@gitster.g>
Hi,
First of all, thanks for the thoughtful response.
Junio C Hamano <gitster@pobox.com> writes:
> - Adding new code here would mean that the result of parsing @{-1}
>   and what wt_status_get_detached_from() will report becomes
>   inconsistent, no?

If I understand correctly, the result of parsing @{-1} is the commit checked out before the current one, so grab_nth_branch_switch() gets the commit we've moved _from_, whereas wt-status::grab_1st_switch() gets the commit we've moved _to_. After a clone, there is no commit we've moved _from_.

> Yes, the head may be detached at some object that is not a local or
> remote branch.  But what is so bad about reporting the fact
> faithfully, i.e., that we are not on any branch?

I thought that we try to avoid showing "Not currently on any branch" as this message is not very user-friendly (see commit b397ea4). Furthermore, showing "HEAD detached at X" where X is the abbreviated hash is more consistent with the behavior of the detached HEAD advice in "git clone", which says

        Note: switching to 'X'
Show 6 quoted lines
> I personally do not very much appreciate the extra info that is
> given by saying "HEAD detached at X" and "HEAD detached from X",
> compared to saying just "Not currently on any branch", especially
> when these X are not concrete branch names or tag names but just
> hexadecimal string that needs to be fed to "git describe" to be
> turned into something that makes sense to humans

It might be better to show "HEAD detached at X" where X is the concrete tag name which was cloned; but since "grab_1st_switch" digs in the reflog for that information, one cannot figure out the tag name that was used when the repository was cloned. I didn't want to complicate the current logic too much, and IMHO showing the abbreviated hash is the best thing we can do, and it is already what we do in certain cases (e.g. after "git checkout --detach").

Previous: Junio C Hamano
Message 5 of 5 in “status: improve info for detached HEAD”
  1. 0/2 status: improve info for detached HEADRoy Eldar, Mar 8, 2023
  2. 1/2 t7508: test status output for detached HEAD after cloneRoy Eldar, Mar 8, 2023
  3. 2/2 status: improve info for detached HEAD after cloneRoy Eldar, Mar 8, 2023
  4. Junio C HamanoMar 8, 2023
  5. Roy EMar 10, 2023

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.