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

Re: Bug in `git branch --delete main` when on other orphan brancht

From
Jeff King <peff@peff.net>
Date
Nov 1, 2022, 21:45 UTC
Message-ID
<Y2GTgB0oTW3rR1HZ@coredump.intra.peff.net>
In-Reply-To
<Y2F+MA+cAsEB0Glb@nand.local>
On Tue, Nov 01, 2022 at 04:14:40PM -0400, Taylor Blau wrote:
Show 21 quoted lines
> Actually, the test doesn't need "other" here, since we aren't actually
> going to delete the target branch (for the exact same reason that you
> pointed out to Martin earlier in the thread).
> 
> So it could actually be as small as something like this:
> 
> --- >8 ---
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 7f605f865b..464d3f610b 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -279,6 +279,13 @@ test_expect_success 'git branch -M and -C fail on detached HEAD' '
>  	test_cmp expect err
>  '
> 
> +test_expect_success 'git branch -d on detached HEAD' '
> +	test_when_finished git checkout main &&
> +	git checkout --orphan orphan &&
> +	test_must_fail git branch -d main 2>err &&
> +	grep "not fully merged" err
> +'

I think there's a more interesting case, which is when "main" has a configured upstream to which it's fully merged. And then the deletion actually succeeds (and the bug is not just giving us a crappy message, but actually doing causing the wrong outcome).

And for that we'd probably not want to use "main", since a successful test will actually delete it. ;)

I'll try later tonight to integrate that test into the patch you've written.

-Peff
Previous: Taylor BlauNext: Taylor Blau
Message 6 of 12 in “Bug in `git branch --delete main` when on other orphan branch”
  1. Martin von ZweigbergkOct 29, 2022
  2. Jeff KingNov 1, 2022
  3. Martin von ZweigbergkNov 1, 2022
  4. Taylor BlauNov 1, 2022
  5. Taylor BlauNov 1, 2022
  6. Jeff KingNov 1, 2022
  7. Taylor BlauNov 2, 2022
  8. branch: gracefully handle '-d' on detached HEADTaylor Blau, Nov 1, 2022
  9. branch: gracefully handle '-d' on orphan HEADJeff King, Nov 2, 2022
  10. Rubén JustoNov 4, 2022
  11. Jeff KingNov 4, 2022
  12. Rubén JustoNov 6, 2022

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.