Skip to content

Commit a0bea09

Browse files
pks-tgitster
authored andcommitted
refs: fix migration of reflogs respecting "core.logAllRefUpdates"
In 246cebe (refs: add support for migrating reflogs, 2024-12-16) we have added support to git-refs(1) to migrate reflogs between reference backends. It was reported [1] though that not we don't migrate reflogs for a subset of references, most importantly "refs/stash". This issue is caused by us still honoring "core.logAllRefUpdates" when trying to migrate reflogs: we do queue the updates, but depending on the value of that config we may decide to just skip writing the reflog entry altogether. And given that: - The default for "core.logAllRefUpdates" is to only create reflogs for branches, remotes, note refs and "HEAD" - "refs/stash" is neither of these ref types. We end up skipping the reflog creation for that particular reference. Fix the bug by setting `REF_FORCE_CREATE_REFLOG`, which instructs the ref backends to create the reflog entry regardless of the config or any preexisting state. [1]: <[email protected]> Reported-by: brian m. carlson <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ddcdc1 commit a0bea09

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ int ref_transaction_update_reflog(struct ref_transaction *transaction,
12821282

12831283
assert(err);
12841284

1285-
flags |= REF_LOG_ONLY | REF_NO_DEREF;
1285+
flags |= REF_LOG_ONLY | REF_FORCE_CREATE_REFLOG | REF_NO_DEREF;
12861286

12871287
if (!transaction_refname_valid(refname, new_oid, flags, err))
12881288
return -1;

t/t1460-refs-migrate.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ do
224224
test_commit --date "100003000 +0700" --no-tag -C repo second &&
225225
test_migration repo "$to_format"
226226
'
227+
228+
test_expect_success "$from_format -> $to_format: stash is retained" '
229+
test_when_finished "rm -rf repo" &&
230+
git init --ref-format=$from_format repo &&
231+
(
232+
cd repo &&
233+
test_commit initial A &&
234+
echo foo >A &&
235+
git stash push &&
236+
echo bar >A &&
237+
git stash push &&
238+
git stash list >expect.reflog &&
239+
test_migration . "$to_format" &&
240+
git stash list >actual.reflog &&
241+
test_cmp expect.reflog actual.reflog
242+
)
243+
'
227244
done
228245
done
229246

0 commit comments

Comments
 (0)