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> 398a1b0Show 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.