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

Re: [PATCH v2] branch: allow deleting dangling branches with --force

From
René Scharfe <l.s.r@web.de>
Date
Aug 26, 2021, 21:01 UTC
Message-ID
<9c999d1f-9263-965d-a0a1-527e1260a6d9@web.de>
In-Reply-To
<xmqqk0k8do27.fsf@gitster.g>
Am 26.08.21 um 21:05 schrieb Junio C Hamano:
Show 8 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>> +	hash=$(git rev-parse HEAD) &&
>> +	objpath=$(echo $hash | sed -e "s|^..|.git/objects/&/|") &&
>> +	git branch --no-track dangling &&
>> +	test_when_finished "test -f $objpath.x && mv $objpath.x $objpath" &&
>
> Do we need test -f here?

If the mv in the next line fails, then test in the cleanup prevents it from adding another confusing error. So it's not really needed, but kinda nice to have.

Show 10 quoted lines
>> +	mv $objpath $objpath.x &&
>> +	git branch --delete --force dangling &&
>
>> +	test -z "$(git for-each-ref refs/heads/dangling)"
>
> It is not wrong per-se, but maybe
>
> 	git show-ref --quiet refs/heads/dangling
>
> is more straight-forward.

Actually it *is* wrong, because that check passes even if the dangling ref still exists due to for-each-ref checking if the ref target exists and just erroring out if it doesn't. I somehow assumed it wouldn't do this needless verification. So we'd need to check its return value:

	git for-each-ref refs/heads/dangling >actual &&
	test_must_be_empty actual

git show-ref fails both if the ref is missing and if it's dangling, so we'd need to check its stderr to distinguish between those cases:

	test_must_fail git show-ref --quiet refs/heads/dangling 2>err &&
	test_must_be_empty err
To avoid these complications we could ask git branch itself:
	test -z $(git branch --list dangling)
René
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 15 of 17 in “branch: allow deleting dangling branches with --force”
  1. branch: allow deleting dangling branches with --forceRené Scharfe, Aug 25, 2021
  2. Junio C HamanoAug 25, 2021
  3. Ævar Arnfjörð BjarmasonAug 25, 2021
  4. René ScharfeAug 26, 2021
  5. Han-Wen NienhuysAug 26, 2021
  6. Junio C HamanoAug 26, 2021
  7. Junio C HamanoAug 26, 2021
  8. Antw: [EXT] Re: [PATCH RESEND] branch: allow deleting dangling branches with ‑‑forceUlrich Windl, Aug 27, 2021
  9. Ævar Arnfjörð BjarmasonAug 27, 2021
  10. René ScharfeAug 26, 2021
  11. Ævar Arnfjörð BjarmasonAug 25, 2021
  12. René ScharfeAug 26, 2021
  13. branch: allow deleting dangling branches with --forceRené Scharfe, Aug 26, 2021
  14. Junio C HamanoAug 26, 2021
  15. René ScharfeAug 26, 2021
  16. Ævar Arnfjörð BjarmasonAug 26, 2021
  17. branch: allow deleting dangling branches with --forceRené Scharfe, Aug 27, 2021

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.