Skip to content

Commit e542d1e

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

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
@@ -560,6 +560,19 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
560560
test_cmp expected atomic/.git/FETCH_HEAD
561561
'
562562

563+
test_expect_success REFFILES 'fetch --atomic fails transaction if reference locked' '
564+
test_when_finished "rm -rf upstream repo" &&
565+
566+
git init upstream &&
567+
git -C upstream commit --allow-empty -m 1 &&
568+
git -C upstream switch -c foobar &&
569+
git clone --mirror upstream repo &&
570+
git -C upstream commit --allow-empty -m 2 &&
571+
touch repo/refs/heads/foobar.lock &&
572+
573+
test_must_fail git -C repo fetch --atomic origin
574+
'
575+
563576
test_expect_success '--refmap="" ignores configured refspec' '
564577
cd "$TRASH_DIRECTORY" &&
565578
git clone "$D" remote-refs &&

0 commit comments

Comments
 (0)