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

Re: [PATCH v2] bisect: fix "reset" when branch is checked out elsewhere

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 6, 2023, 22:29 UTC
Message-ID
<xmqqwn4u2ztc.fsf@gitster.g>
In-Reply-To
<ada28944-6e9e-d4e7-74c9-ffadaf406e1f@gmail.com>
Rubén Justo <rjusto@gmail.com> writes:
Show 7 quoted lines
> Since 1d0fa89 (checkout: add --ignore-other-wortrees, 2015-01-03) we
> have a safety valve in checkout/switch to prevent the same branch from
> being checked out simultaneously in multiple worktrees.
>
> If a branch is bisected in a worktree while also being checked out in
> another worktree; when the bisection is finished, checking out the
> branch back in the current worktree may fail.

Sorry for asking possibly the same question again (which may mean that the phrasing of this paragraph is misleading), but isn't it a good thing if in this sequence:

 - I checkout 'main' and start bisecting (BISECT_HEAD says 'main');
 - I then checkout 'main' in another worktree; I may even make a
   commit or two, or even rename 'main' to 'master'.
 - I finish bisection and "bisect reset" tries to take me back to
   'main', which may notice that 'main' is checked out in the other
   worktree, and fail.

the last one failed? After the above sequence, I now have two worktrees, both checking out 'main', and it is exactly the situation the safety valve tries to prevent from occuring, no?

Or is the new behaviour considered better because the third step would try to check out 'main' that is checked out elsewhere only if the second step was forced, so the person who decided to touch 'main' in another worktree should already be aware of the risk and we should disable the safety valve in the third step automatically?

I am not sure if that is a sensible argument, but if that is the case, let's spell it out in the proposed log message.

Thanks.
Show 17 quoted lines
>  builtin/bisect.c            |  5 ++++-
>  t/t6030-bisect-porcelain.sh | 23 +++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/bisect.c b/builtin/bisect.c
> index 7301740267..46fba8db50 100644
> --- a/builtin/bisect.c
> +++ b/builtin/bisect.c
> @@ -244,7 +244,10 @@ static int bisect_reset(const char *commit)
>  		struct child_process cmd = CHILD_PROCESS_INIT;
>  
>  		cmd.git_cmd = 1;
> -		strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL);
> +		strvec_pushl(&cmd.args, "checkout", NULL);
> +		if (!commit)
> +			strvec_pushl(&cmd.args, "--ignore-other-worktrees", NULL);
> +		strvec_pushl(&cmd.args, branch.buf, "--", NULL);

OK, so this time around "git bisect reset" to go back to the original branch gets --ignore-other-worktrees but "git bisect reset HEAD" or other forms that names a branch still gets the safety. That makes the blast radius smaller, but I am not 100% sure if loosening the safety is a good thing.

Previous: Rubén JustoNext: Rubén Justo
Message 9 of 15 in “bisect: fix "reset" when branch is checked out elsewhere”
  1. bisect: fix "reset" when branch is checked out elsewhereRubén Justo, Jan 22, 2023
  2. Junio C HamanoJan 23, 2023
  3. Rubén JustoJan 26, 2023
  4. Junio C HamanoJan 26, 2023
  5. Junio C HamanoJan 26, 2023
  6. Rubén JustoFeb 4, 2023
  7. Junio C HamanoFeb 6, 2023
  8. bisect: fix "reset" when branch is checked out elsewhereRubén Justo, Feb 4, 2023
  9. Junio C HamanoFeb 6, 2023
  10. Rubén JustoFeb 8, 2023
  11. Junio C HamanoFeb 8, 2023
  12. Rubén JustoFeb 8, 2023
  13. Eric SunshineFeb 15, 2023
  14. Rubén JustoFeb 15, 2023
  15. bisect: fix "reset" when branch is checked out elsewhereRubén Justo, Feb 20, 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.