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

Re: [PATCH v4] checkout/switch: disallow checking out same branch in multiple worktrees

From
Carlo Arenas <carenas@gmail.com>
Date
Mar 24, 2023, 03:49 UTC
Message-ID
<CAPUEspj_Bh+LgYLnWfeBdcq_uV5Cbou-7H51GLFjzSa5Qzby9w@mail.gmail.com>
In-Reply-To
<xmqq355wbaar.fsf@gitster.g>
On Wed, Mar 22, 2023 at 5:06 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 43 quoted lines
>
> Phillip Wood <phillip.wood123@gmail.com> writes:
>
> > Hi Carlo
> > ...
> > As I said before, it would be much easier for everyone else to
> > understand the changes if you wrote out what they were rather than
> > saying "look at the tests"....
> > ...
> >> +    if (!opts->ignore_other_worktrees && !opts->force_detach &&
> >> +        check_branch_path && ref_exists(check_branch_path)) {
> >
> > I think check_branch_path is NULL if opts->ignore_other_worktrees is
> > set so we could maybe lose "!opts->ignore_other_worktrees" here (or
> > possibly below where you set check_branch_path).
> > ...
> >> ...
> >> +            if (!opts->ignore_other_worktrees && !check_branch_path && new_branch_info->path)
> >> +                    check_branch_path = xstrdup(new_branch_info->path);
> >
> > I'm a bit confused what this is doing.
> > ...
> >> +test_expect_success 'allow checkout/reset from the conflicted branch' '
> >
> > I'm not sure what "the conflicted branch" means (it reminds we of
> > merge conflicts). Is this just testing that "checkout -b/B <branch>
> > <start-point>" works?
> > ...
> >> +test_expect_success 'and not die on re-checking out current branch even if conflicted' '
> >
> > I think 'allow re-checking out ...' would be clearer, again I'm not
> > sure what's conflicted here.
> > ...
> >>   -test_expect_success 'not die on re-checking out current branch' '
> >> +test_expect_failure 'unless using force without --ignore-other-worktrees' '
> >
> > This test passes for me - what's the reason for changing from
> > test_expect_success to test_expect_failure?
> >
> > Thanks for working on this
>
> are there remaining things
> to be done and issues to be resolved before we can see v5?

it interacted with another branch (rj/avoid-switching-to-already-used-branch) that was just recently merged to master.

it also was probably too aggressive as pointed[1] by Phillip after my explanation of the change of behaviour as quoted:

Show 17 quoted lines
>> Using`checkout` for simplicity, but also applies to `switch`,
>>
>>    % git worktree list
>>    .../base  6a45aba [main]
>>    % git worktree add -f ../other main
>>    Preparing worktree (checking out 'main')
>>    HEAD is now at 6a45aba init
>>    % cd ../other
>>    % git checkout main
>>    Already on 'main'
>>    % git checkout -B main
>>    fatal: 'main' is already checked out at '.../base'
>
> Thanks for explaining that. If there is no <start-point> given we don't
> reset the branch so it seems a bit harsh to error out here. For "git
> checkout -B <branch> <start-point>" when <branch> is checked out in
> another worktree requiring --ignore-other-worktrees makes sense.

I wasn't sure on how to proceed from there, but will come with a v5 to discuss further.

Carlo
[1] https://lore.kernel.org/git/a848b7d5-fd40-b043-7ed9-1672f65312e6@dunelm.org.uk/
Previous: Junio C HamanoNext: Rubén Justo
Message 23 of 24 in “builtin/checkout: check the branch used in -B with worktrees”
  1. builtin/checkout: check the branch used in -B with worktreesCarlo Marcelo Arenas Belón, Jan 16, 2023
  2. Eric SunshineJan 16, 2023
  3. Rubén JustoJan 17, 2023
  4. Carlo ArenasJan 18, 2023
  5. checkout/switch: disallow checking out same branch in multiple worktreesCarlo Marcelo Arenas Belón, Jan 18, 2023
  6. Junio C HamanoJan 18, 2023
  7. Carlo ArenasJan 18, 2023
  8. Junio C HamanoJan 18, 2023
  9. Junio C HamanoJan 18, 2023
  10. checkout/switch: disallow checking out same branch in multiple worktreesCarlo Marcelo Arenas Belón, Jan 19, 2023
  11. Re* [PATCH v3] checkout/switch: disallow checking out same branch in multiple worktreesJunio C Hamano, Jan 19, 2023
  12. Carlo ArenasJan 19, 2023
  13. Phillip WoodJan 19, 2023
  14. Junio C HamanoJan 20, 2023
  15. Carlo ArenasJan 20, 2023
  16. Carlo ArenasJan 20, 2023
  17. checkout/switch: disallow checking out same branch in multiple worktreesCarlo Marcelo Arenas Belón, Jan 20, 2023
  18. Phillip WoodJan 20, 2023
  19. Carlo ArenasJan 20, 2023
  20. Phillip WoodJan 27, 2023
  21. Rubén JustoMay 14, 2023
  22. Junio C HamanoMar 23, 2023
  23. Carlo ArenasMar 24, 2023
  24. Rubén JustoMay 14, 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.