Skip to content

Commit 5676db2

Browse files
committed
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
2 parents 878e727 + 09b2aa3 commit 5676db2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ static int run_transaction_hook(struct ref_transaction *transaction,
20442044
if (hook == &hook_not_found)
20452045
return ret;
20462046
if (!hook)
2047-
hook = find_hook("reference-transaction");
2047+
hook = xstrdup_or_null(find_hook("reference-transaction"));
20482048
if (!hook) {
20492049
hook = &hook_not_found;
20502050
return ret;

t/t1416-ref-transaction-hooks.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_description='reference transaction hooks'
77
test_expect_success setup '
88
mkdir -p .git/hooks &&
99
test_commit PRE &&
10+
PRE_OID=$(git rev-parse PRE) &&
1011
test_commit POST &&
1112
POST_OID=$(git rev-parse POST)
1213
'
@@ -106,4 +107,30 @@ test_expect_success 'hook gets all queued updates in aborted state' '
106107
test_cmp expect actual
107108
'
108109

110+
test_expect_success 'interleaving hook calls succeed' '
111+
test_when_finished "rm -r target-repo.git" &&
112+
113+
git init --bare target-repo.git &&
114+
115+
write_script target-repo.git/hooks/reference-transaction <<-\EOF &&
116+
echo $0 "$@" >>actual
117+
EOF
118+
119+
write_script target-repo.git/hooks/update <<-\EOF &&
120+
echo $0 "$@" >>actual
121+
EOF
122+
123+
cat >expect <<-EOF &&
124+
hooks/update refs/tags/PRE $ZERO_OID $PRE_OID
125+
hooks/reference-transaction prepared
126+
hooks/reference-transaction committed
127+
hooks/update refs/tags/POST $ZERO_OID $POST_OID
128+
hooks/reference-transaction prepared
129+
hooks/reference-transaction committed
130+
EOF
131+
132+
git push ./target-repo.git PRE POST &&
133+
test_cmp expect target-repo.git/actual
134+
'
135+
109136
test_done

0 commit comments

Comments
 (0)