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
Taylor Blau <me@ttaylorr.com>
Date
Nov 1, 2022, 20:14 UTC
Message-ID
<Y2F+MA+cAsEB0Glb@nand.local>
In-Reply-To
<Y2F9lkCWf/2rjT2E@nand.local>
On Tue, Nov 01, 2022 at 04:12:06PM -0400, Taylor Blau wrote:
Show 24 quoted lines
> Yeah, that looks reasonable to me. Presumably we want a small test, as
> well, but I doubt that is any more complicated than:
>
> --- 8< ---
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 7f605f865b..6ace22f7ce 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -279,6 +279,14 @@ 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 branch -D other" &&
> +	git branch other &&
> +	git checkout --orphan orphan &&
> +	test_must_fail git branch -d other 2>err &&
> +	grep "not fully merged" err
> +'
> +
>  test_expect_success 'git branch -v -d t should work' '
>  	git branch t &&
>  	git rev-parse --verify refs/heads/t &&
> --- >8 ---

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
+'
+
 test_expect_success 'git branch -v -d t should work' '
 	git branch t &&
 	git rev-parse --verify refs/heads/t &&
--- 8< ---

Thanks,
Taylor
Previous: Taylor BlauNext: Jeff King
Message 5 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.