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

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

From
Carlo Arenas <carenas@gmail.com>
Date
Jan 18, 2023, 07:58 UTC
Message-ID
<CAPUEspjmFJUjZmNBH=f_-TY3hYnOtgVjBY-YtWuo15eg3a+5cQ@mail.gmail.com>
In-Reply-To
<xmqq5yd48hcb.fsf@gitster.g>
On Tue, Jan 17, 2023 at 10:52 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
>
> Carlo Marcelo Arenas Belón  <carenas@gmail.com> writes:
>
> > As reflected on the tests, this will change the behaviour of those
> > commands when they are invoked in a worktree that has that requested
> > branch checked out, as that matches the logic used by branch, is safer
> > (assuming both commands are user facing) and can be overriden with an
> > existing flag.
>
> ... meaning you can "--force", or something else?  Allowing an
> existing option to be used as the safety valve does make sense,
> especially if the option is something users are already familiar
> with (like "--force") and naturally expected to work.
the following is the way to override:
$ git checkout --ignore-other-worktrees -B foo
Show 7 quoted lines
> There might need an documentation update.  Back when "checkout -b"
> and "branch" was written, there wasn't "multiple worktrees connected
> to a single repository" hence there was no need to provide safety
> against checking out the same branch in two different places.  "git
> branch" might have learned to give that safety while "git checkout
> -b", which _ought_ to be equivalent to "git branch" followed by "git
> checkout", might have forgot to do so.

Not sure if it was originally forgotten, but it is definitely working now; this change only fixes the uppercase (-B) version.

Show 6 quoted lines
> After this change, it may
> still be correct to say that "checkout -b" is equivalent to "branch"
> followed by "checkout", but if the documentation to "branch" talks
> about this safety, it probably deserves to be mentioned in the
> documentation to "checkout -b", as well, if only to give an appropriate
> place to talk about how to override it "with an existing flag".

Interestingly, when the flag was added in 1d0fa898ea (checkout: add --ignore-other-wortrees, 2015-01-03), it was only added to `checkout`.

`git branch` has no flag and will die even when `-f` is used
Carlo
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 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.