aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-08-17 17:02:40 -0700
committerJunio C Hamano <gitster@pobox.com>2020-08-17 17:02:41 -0700
commit5676db26129bf18e77bb821d832b44c022dc9f47 (patch)
tree08cf277bcd65b13d73a5ae08f99a75fc4e4da94c
parent878e727637ec5815ccb3301eb994a54df95b21b8 (diff)
parent09b2aa30c916bd6facb47a06711755f043b6f37e (diff)
downloadgit-5676db26129bf18e77bb821d832b44c022dc9f47.tar.xz
Merge branch 'ps/ref-transaction-hook'
The logic to find the ref transaction hook script attempted to cache the path to the found hook without realizing that it needed to keep a copied value, as the API it used returned a transitory buffer space. This has been corrected. * ps/ref-transaction-hook: t1416: avoid hard-coded sha1 ids refs: fix interleaving hook calls with reference-transaction hook
-rw-r--r--refs.c2
-rwxr-xr-xt/t1416-ref-transaction-hooks.sh27
2 files changed, 28 insertions, 1 deletions
diff --git a/refs.c b/refs.c
index 9e28912f73..ac2772fbda 100644
--- a/refs.c
+++ b/refs.c
@@ -2044,7 +2044,7 @@ static int run_transaction_hook(struct ref_transaction *transaction,
if (hook == &hook_not_found)
return ret;
if (!hook)
- hook = find_hook("reference-transaction");
+ hook = xstrdup_or_null(find_hook("reference-transaction"));
if (!hook) {
hook = &hook_not_found;
return ret;
diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
index da58d867a5..f6e741c6c0 100755
--- a/t/t1416-ref-transaction-hooks.sh
+++ b/t/t1416-ref-transaction-hooks.sh
@@ -7,6 +7,7 @@ test_description='reference transaction hooks'
test_expect_success setup '
mkdir -p .git/hooks &&
test_commit PRE &&
+ PRE_OID=$(git rev-parse PRE) &&
test_commit POST &&
POST_OID=$(git rev-parse POST)
'
@@ -106,4 +107,30 @@ test_expect_success 'hook gets all queued updates in aborted state' '
test_cmp expect actual
'
+test_expect_success 'interleaving hook calls succeed' '
+ test_when_finished "rm -r target-repo.git" &&
+
+ git init --bare target-repo.git &&
+
+ write_script target-repo.git/hooks/reference-transaction <<-\EOF &&
+ echo $0 "$@" >>actual
+ EOF
+
+ write_script target-repo.git/hooks/update <<-\EOF &&
+ echo $0 "$@" >>actual
+ EOF
+
+ cat >expect <<-EOF &&
+ hooks/update refs/tags/PRE $ZERO_OID $PRE_OID
+ hooks/reference-transaction prepared
+ hooks/reference-transaction committed
+ hooks/update refs/tags/POST $ZERO_OID $POST_OID
+ hooks/reference-transaction prepared
+ hooks/reference-transaction committed
+ EOF
+
+ git push ./target-repo.git PRE POST &&
+ test_cmp expect target-repo.git/actual
+'
+
test_done