Skip to content

Commit 518ed01

Browse files
committed
Merge branch 'jt/ref-transaction-abort-fix'
A ref transaction corner case fix. * jt/ref-transaction-abort-fix: builtin/fetch: avoid aborting closed reference transaction
2 parents 959760d + b9fadee commit 518ed01

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
@@ -1859,8 +1859,15 @@ static int do_fetch(struct transport *transport,
18591859
goto cleanup;
18601860

18611861
retcode = ref_transaction_commit(transaction, &err);
1862-
if (retcode)
1862+
if (retcode) {
1863+
/*
1864+
* Explicitly handle transaction cleanup to avoid
1865+
* aborting an already closed transaction.
1866+
*/
1867+
ref_transaction_free(transaction);
1868+
transaction = NULL;
18631869
goto cleanup;
1870+
}
18641871
}
18651872

18661873
commit_fetch_head(&fetch_head);

t/t5510-fetch.sh

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

540+
test_expect_success REFFILES 'fetch --atomic fails transaction if reference locked' '
541+
test_when_finished "rm -rf upstream repo" &&
542+
543+
git init upstream &&
544+
git -C upstream commit --allow-empty -m 1 &&
545+
git -C upstream switch -c foobar &&
546+
git clone --mirror upstream repo &&
547+
git -C upstream commit --allow-empty -m 2 &&
548+
touch repo/refs/heads/foobar.lock &&
549+
550+
test_must_fail git -C repo fetch --atomic origin
551+
'
552+
540553
test_expect_success '--refmap="" ignores configured refspec' '
541554
cd "$TRASH_DIRECTORY" &&
542555
git clone "$D" remote-refs &&

0 commit comments

Comments
 (0)