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

Re: [PATCH 2/3] worktree: warn when removing a worktree with orphan commits

From
Rubén Justo <rjusto@gmail.com>
Date
Apr 27, 2023, 23:08 UTC
Message-ID
<592c7265-c8af-bd3c-561d-be22e34d61d6@gmail.com>
In-Reply-To
<xmqqwn1xnahy.fsf@gitster.g>
On 26-abr-2023 22:46:01, Junio C Hamano wrote:
> Rubén Justo <rjusto@gmail.com> writes:

The message: "Previous HEAD position was", which we have since dc9195ac78 (Let git-checkout always drop any detached head, 2007-02-03), describes a detached HEAD that has been left behind.

In 8e2dc6ac06 (commit: give final warning when reattaching HEAD to leave commits behind, 2011-02-18) we moved this message to a new function, orphaned_commit_warning(). We still show the message if the HEAD left behind is detached. However, if the HEAD left behind is detached _and_ _not connected_ to any ref, instead of the original message, we show a warning.

In this series, we want to use that function to show the same warning when the user removes a worktree whose HEAD is detached and _not connected_ to any ref. However, if the HEAD is detached but connected, the original message introduced in dc9195ac78 needs to be adjusted.

Show 5 quoted lines
> > Maybe "HEAD position was" fits for both usages.  This is how it would
> > look like:
> > ...
> > I think, if there are no objections or better suggestions, I'll re-roll
> > with "HEAD was at". 
This is about the message introduced in dc9195ac78, but...
> But does it convey the more important point?  The reason why "HEAD
I think you are referring to the warning.
Starting from a situation like:
   $ git checkout -b foo
   Switched to a new branch 'foo'
   $ git checkout --detach
   HEAD is now at 47ab99a
   $ git commit --allow-empty -m dangling
   [detached HEAD 398a1b0] dangling
   $ git worktree add --detach foo-wt
   Preparing worktree (detached HEAD 398a1b0)
   HEAD is now at 398a1b0 dangling
If we switch to 'foo' in the current worktree, the message is:
   $ git checkout foo
   Warning: you are leaving 1 commit behind, not connected to
   any of your branches:
   
     398a1b0 dangling 
   
   If you want to keep it by creating a new branch, this may be a good time
   to do so with:
   
    git branch <new-branch-name> 398a1b0
   
   Switched to branch 'foo'

And -- this is what we are adding in this series -- the same message if we remove the worktree 'foo-wt':

   $ git worktree remove foo-wt
   Warning: you are leaving 1 commit behind, not connected to
   any of your branches:
   
     398a1b0 dangling 
   
   If you want to keep it by creating a new branch, this may be a good time
   to do so with:
   
    git branch <new-branch-name> 398a1b0
Show 13 quoted lines
> > Maybe "HEAD position was" fits for both usages.  This is how it would
> > look like:
> >
> >    $ git checkout -
> >    HEAD position was 7906992 commit-b
> >    HEAD is now at 2efe05c commit-a
> 
> Here "git checkout" reports the lost HEAD and then the end result.
> 
> >    $ git worktree add test --detach && git worktree remove test
> >    Preparing worktree (detached HEAD 2efe05c)
> >    HEAD is now at 2efe05c commit-a
> >    HEAD position was 2efe05c commit-a

I apologize, the examples were confusing. I though it was a good idea to show the new message next to other messages where we also refer to the HEAD position.

Previous: Junio C HamanoNext: Rubén Justo
Message 9 of 12 in “warn when unreachable commits are left behind”
  1. 0/3 warn when unreachable commits are left behindRubén Justo, Apr 22, 2023
  2. 1/3 checkout: move orphaned_commit_warning()Rubén Justo, Apr 22, 2023
  3. 2/3 worktree: warn when removing a worktree with orphan commitsRubén Justo, Apr 22, 2023
  4. Junio C HamanoApr 24, 2023
  5. Rubén JustoApr 26, 2023
  6. Junio C HamanoApr 27, 2023
  7. Eric SunshineApr 27, 2023
  8. Junio C HamanoApr 28, 2023
  9. Rubén JustoApr 27, 2023
  10. 3/3 checkout: warn when unreachable commits after using --orphanRubén Justo, Apr 22, 2023
  11. Andrei RybakApr 27, 2023
  12. Rubén JustoApr 27, 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.