Skip to content

Commit

Permalink
update-ref: do set reflog's old_oid
Browse files Browse the repository at this point in the history
In git 2.48.1, the `git update-ref` subcommand no longer correctly
updates the reflog in some cases. Specifically, it appears that the
`old_oid` field will not be updated when modifying a branch referenced
by another symbolic ref (e.g. HEAD). This doesn't break the `git
reflog` subcommand, but does break references like `HEAD@{1}`, which
appear to read the `old_oid` field:

  git init -b main
  git commit --allow-empty -m "A"
  git commit --allow-empty -m "B"
  git update-ref -m "reason" refs/heads/main HEAD~ HEAD

The `old_oid` field is now empty (all zeroes). This is only the case in
derived reflogs (in this case .git/logs/HEAD). The reflog for
`refs/heads/main` appears to be updated correctly.

This was broken in 297c09e (refs: allow multiple reflog entries for
the same refname, 2024-12-16).

The reason for that was that there was assumed the flow of
`lock_ref_for_update()` for reflog only updates was to capture the lock
only. But this is wrong since this misses the `old_oid` population. As
such this patch is the correct fix.

Reported-by: Nika Layzell <[email protected]>
Acked-by: Karthik Nayak <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
peff authored and dscho committed Jan 22, 2025
1 parent b7a9905 commit 86d0c30
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2615,9 +2615,6 @@ static int lock_ref_for_update(struct files_ref_store *refs,

update->backend_data = lock;

if (update->flags & REF_LOG_ONLY)
goto out;

if (update->type & REF_ISSYMREF) {
if (update->flags & REF_NO_DEREF) {
/*
Expand Down

0 comments on commit 86d0c30

Please sign in to comment.