Skip to content

Commit 3519492

Browse files
KarthikNayakpeff
authored andcommitted
refs: fix creation of reflog entries for symrefs
The commit 297c09e (refs: allow multiple reflog entries for the same refname, 2024-12-16) added logic to exit early in `lock_ref_for_update()` after obtaining the required lock. This was added as a performance optimization on a false assumption that no further processing was required for reflog-only updates. However the assumption was wrong. For a symref's reflog entry, the update needs to be populated with the old_oid value, but the early exit skipped this necessary step. This caused a bug in Git 2.48 in the files backend where target references of symrefs being updated would create a corrupted reflog entry for the symref since the old_oid is not populated. Everything the early exit skipped in the code path is necessary for both regular and symbolic ref, so eliminate the mistaken optimization, and also add a test to ensure that such an issue doesn't arise in the future. Reported-by: Nika Layzell <[email protected]> Co-authored-by: Jeff King <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ddcdc1 commit 3519492

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

refs/files-backend.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,9 +2611,6 @@ static int lock_ref_for_update(struct files_ref_store *refs,
26112611

26122612
update->backend_data = lock;
26132613

2614-
if (update->flags & REF_LOG_ONLY)
2615-
goto out;
2616-
26172614
if (update->type & REF_ISSYMREF) {
26182615
if (update->flags & REF_NO_DEREF) {
26192616
/*

t/t1400-update-ref.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,4 +2068,13 @@ do
20682068

20692069
done
20702070

2071+
test_expect_success 'update-ref should also create reflog for HEAD' '
2072+
test_commit to-rewind &&
2073+
git rev-parse HEAD >expect &&
2074+
head=$(git symbolic-ref HEAD) &&
2075+
git update-ref --create-reflog "$head" HEAD~ &&
2076+
git rev-parse HEAD@{1} >actual &&
2077+
test_cmp expect actual
2078+
'
2079+
20712080
test_done

0 commit comments

Comments
 (0)