summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-04-16 13:54:17 -0700
committerJunio C Hamano <gitster@pobox.com>2025-04-16 13:54:17 -0700
commit518ed014f6f2732000afdb13ef5354dd96f04746 (patch)
treec55ffe48809fe07ef3298f70b830b5e336a242f4
parent959760dc42880d7b8fc878db9221d8ced1e4c48f (diff)
parentb9fadeead74df1f4fa4a4177e478903d63e600f5 (diff)
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
-rw-r--r--builtin/fetch.c9
-rwxr-xr-xt/t5510-fetch.sh13
2 files changed, 21 insertions, 1 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 1c6573345e..5694a3a27f 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1859,8 +1859,15 @@ static int do_fetch(struct transport *transport,
goto cleanup;
retcode = ref_transaction_commit(transaction, &err);
- if (retcode)
+ if (retcode) {
+ /*
+ * Explicitly handle transaction cleanup to avoid
+ * aborting an already closed transaction.
+ */
+ ref_transaction_free(transaction);
+ transaction = NULL;
goto cleanup;
+ }
}
commit_fetch_head(&fetch_head);
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 5f350facf5..690755d2a8 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -537,6 +537,19 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
test_cmp expected atomic/.git/FETCH_HEAD
'
+test_expect_success REFFILES 'fetch --atomic fails transaction if reference locked' '
+ test_when_finished "rm -rf upstream repo" &&
+
+ git init upstream &&
+ git -C upstream commit --allow-empty -m 1 &&
+ git -C upstream switch -c foobar &&
+ git clone --mirror upstream repo &&
+ git -C upstream commit --allow-empty -m 2 &&
+ touch repo/refs/heads/foobar.lock &&
+
+ test_must_fail git -C repo fetch --atomic origin
+'
+
test_expect_success '--refmap="" ignores configured refspec' '
cd "$TRASH_DIRECTORY" &&
git clone "$D" remote-refs &&