Skip to content

Commit b0f6b6b

Browse files
pks-tgitster
authored andcommitted
refs/reftable: don't fail empty transactions in repo without HEAD
Under normal circumstances, it shouldn't ever happen that a repository has no HEAD reference. In fact, git-update-ref(1) would fail any request to delete the HEAD reference, and a newly initialized repository always pre-creates it, too. We have however changed git-clone(1) to partially initialize the refdb just up to the point where remote helpers can find the repository. With that change, we are going to run into a situation where repositories have no refs at all. Now there is a very particular edge case in this situation: when preparing an empty ref transacton, we end up returning whatever value `read_ref_without_reload()` returned to the caller. Under normal conditions this would be fine: "HEAD" should usually exist, and thus the function would return `0`. But if "HEAD" doesn't exist, the function returns a positive value which we end up returning to the caller. Fix this bug by resetting the return code to `0` and add a test. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6818ff commit b0f6b6b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

refs/reftable-backend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
821821
&head_referent, &head_type);
822822
if (ret < 0)
823823
goto done;
824+
ret = 0;
824825

825826
for (i = 0; i < transaction->nr; i++) {
826827
struct ref_update *u = transaction->updates[i];

t/t0610-reftable-basics.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,19 @@ test_expect_success 'ref transaction: writes are synced' '
328328
EOF
329329
'
330330

331+
test_expect_success 'ref transaction: empty transaction in empty repo' '
332+
test_when_finished "rm -rf repo" &&
333+
git init repo &&
334+
test_commit -C repo --no-tag A &&
335+
COMMIT=$(git -C repo rev-parse HEAD) &&
336+
git -C repo update-ref -d refs/heads/main &&
337+
test-tool -C repo ref-store main delete-refs REF_NO_DEREF msg HEAD &&
338+
git -C repo update-ref --stdin <<-EOF
339+
prepare
340+
commit
341+
EOF
342+
'
343+
331344
test_expect_success 'pack-refs: compacts tables' '
332345
test_when_finished "rm -rf repo" &&
333346
git init repo &&

0 commit comments

Comments
 (0)