# Reftable writes wrong HEAD reflog when a transaction updates HEAD's target

_The bug, which also affects the files backend depending on update order, may lead to moving reflog logic into the generic refs layer._

Section: Bugs. Edition of 2026-11-09. Written by an AI editor from the thread "reftable: wrong HEAD reflog when its target is updated in the same transaction" (8 messages): https://gitlist.dev/t/66806

井上司 reported that with the reftable backend, a transaction that updates a branch and points HEAD at it via `symref-update` records the branch's old value in the HEAD reflog. If the branch is created in the same transaction, no HEAD reflog entry is written. The report included a reproduction on master using `git update-ref --stdin`.

The reporter first said the files backend handled both cases correctly. In a follow-up, they corrected that: the files backend commits updates one by one in queued order, so the reflog is right only when the branch update precedes HEAD. With `symref-update HEAD` first, files also records the old oid, or no entry.

The reporter proposed a helper in refs.c that returns the new oid of a ref updated in the same transaction, which both backends would consult before falling back to refs_resolve_ref_unsafe().

Karthik Nayak said the files backend only escapes the issue because it is not atomic. He said the helper would work, but any future backend supporting atomic transactions would have the same bug. He suggested moving reflog logic into the generic refs.c layer, which already sees all updates in a transaction and could compute the reflog values. Backends would then receive the reflog entries to write.

No patch has been posted, and the choice between the helper and the refs.c approach is open.
