Skip to content

Commit b653d86

Browse files
committed
Merge branch 'jt/ref-transaction-abort-fix' into next
A ref transaction corner case fix. * jt/ref-transaction-abort-fix: builtin/fetch: avoid aborting closed reference transaction
2 parents c9b6a7b + b9fadee commit b653d86

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

builtin/fetch.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,8 +1844,15 @@ static int do_fetch(struct transport *transport,
18441844
goto cleanup;
18451845

18461846
retcode = ref_transaction_commit(transaction, &err);
1847-
if (retcode)
1847+
if (retcode) {
1848+
/*
1849+
* Explicitly handle transaction cleanup to avoid
1850+
* aborting an already closed transaction.
1851+
*/
1852+
ref_transaction_free(transaction);
1853+
transaction = NULL;
18481854
goto cleanup;
1855+
}
18491856
}
18501857

18511858
commit_fetch_head(&fetch_head);

t/t5510-fetch.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,19 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
554554
test_cmp expected atomic/.git/FETCH_HEAD
555555
'
556556

557+
test_expect_success REFFILES 'fetch --atomic fails transaction if reference locked' '
558+
test_when_finished "rm -rf upstream repo" &&
559+
560+
git init upstream &&
561+
git -C upstream commit --allow-empty -m 1 &&
562+
git -C upstream switch -c foobar &&
563+
git clone --mirror upstream repo &&
564+
git -C upstream commit --allow-empty -m 2 &&
565+
touch repo/refs/heads/foobar.lock &&
566+
567+
test_must_fail git -C repo fetch --atomic origin
568+
'
569+
557570
test_expect_success '--refmap="" ignores configured refspec' '
558571
cd "$TRASH_DIRECTORY" &&
559572
git clone "$D" remote-refs &&

0 commit comments

Comments
 (0)