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

Re: [PATCH 4/4] refs: do not clobber dangling symrefs

From
Jeff King <peff@peff.net>
Date
Sep 22, 2025, 17:21 UTC
Message-ID
<20250922172140.GB2202085@coredump.intra.peff.net>
In-Reply-To
<xmqqwm5qv5xh.fsf@gitster.g>
On Mon, Sep 22, 2025 at 08:54:34AM -0700, Junio C Hamano wrote:
Show 17 quoted lines
> Toon Claes <toon@iotcl.com> writes:
> 
> > We use `update FOO_HEAD 000...000 000..000` to delete a symref, if that symref
> > is dangling (otherwise the old oid would have resolved to something). I've
> > attached a patch that would allow this (on top of your patches). Do you think it
> > makes sense to allow this scenario?
> > ...
> > +	test_when_finished "git update-ref -d refs/heads/dangling" &&
> > +	git symbolic-ref refs/heads/dangling refs/heads/does-not-exist &&
> > +	echo "update refs/heads/dangling $Z $Z" >stdin &&
> > +	git update-ref --no-deref --stdin <stdin &&
> 
> "git update-ref --help" seems to show that the "--stdin" mode has a
> separate command that is designed for exactly the purpose of removing
> a symbolic ref, though.  If you are changing the semantics of "update"
> to make it safer while dealing with a dangling symbolic ref, do you
> also need to touch the code path that handles "symref-delete" command?

I don't think so. Whatever we are trying to write (whether a regular ref, a symref, or a deletion), the "check the old value" code path ends up in the same place.

IMHO the directives for "update-ref --stdin" are a bit mis-designed. All of update/delete/verify should accept either "old-oid" or "old-target" (you do not need it for create, which always implies an old-oid of all-zeroes).

And then symref-* is used when you want the _new_ thing to be a symref. So symref-delete is not needed at all. You just have symref-* directives for create/update/verify. Which almost could be replaced by "ref <new-target>", but IIRC there was some syntactic ambiguity (because we allow new-target to be a ref, so you'd have to pick some invalid name like ":symref").

It is probably too late now to switch from "symref-update foo" to "update :ref foo" (and again, I think that may have even been considered and rejected). But we could add support for "ref <old-target>" to the non-symref commands. That is not just a syntactic weakness, but something you literally _can't_ do now (convert a symref into a regular ref atomically).

Anyway, all very off-topic for Toon's issue, though. I think his patch as-is does the right thing for his case, if we want to loosen it for historical reasons (see my other response).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 22 in “dangling symrefs and fetchRemoteHEAD=create”
  1. 0/4 dangling symrefs and fetchRemoteHEAD=createJeff King, Aug 19, 2025
  2. Jeff KingAug 19, 2025
  3. 1/4 t5510: make confusing config cleanup more explicitJeff King, Aug 19, 2025
  4. Eric SunshineAug 19, 2025
  5. Eric SunshineAug 19, 2025
  6. Jeff KingAug 19, 2025
  7. 2/4 t5510: stop changing top-level working directoryJeff King, Aug 19, 2025
  8. 3/4 t5510: prefer "git -C" to subshell for followRemoteHEAD testsJeff King, Aug 19, 2025
  9. SZEDER GáborAug 24, 2025
  10. Junio C HamanoAug 25, 2025
  11. Jeff KingAug 26, 2025
  12. Junio C HamanoAug 26, 2025
  13. 4/4 refs: do not clobber dangling symrefsJeff King, Aug 19, 2025
  14. Patrick SteinhardtAug 20, 2025
  15. Jeff KingAug 20, 2025
  16. Toon ClaesSep 22, 2025
  17. Junio C HamanoSep 22, 2025
  18. Jeff KingSep 22, 2025
  19. Junio C HamanoSep 22, 2025
  20. Jeff KingSep 22, 2025
  21. Toon ClaesSep 23, 2025
  22. Jeff KingSep 23, 2025

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.