From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Derrick Stolee" <derrickstolee@github.com>,
"Adam Spiers" <git@adamspiers.org>, "Jeff King" <peff@peff.net>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 10/13] test-lib-functions: add and use a "write_hook" wrapper
Date: Sun, 12 Dec 2021 21:13:20 +0100 [thread overview]
Message-ID: <patch-10.13-ca55471d134-20211212T201308Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.13-00000000000-20211212T201308Z-avarab@gmail.com>
Add a "write_hook" wrapper for the common case of "write_script
.git/hooks/<NAME>". This also accepts a "-C" option like
"test_commit". Let's convert various trivial cases of "write_script"
over to it.
For now this doesn't have much of an advantage, but in a subsequent
commit we'll implicitly create the leading "hooks" directory. This
will help us get rid of our --template dependency for "hooks".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
t/t1416-ref-transaction-hooks.sh | 14 +++++++-------
t/t5406-remote-rejects.sh | 2 +-
t/t5409-colorize-remote-messages.sh | 2 +-
t/t5411-proc-receive-hook.sh | 4 ++--
t/t5510-fetch.sh | 6 +++---
t/t5516-fetch-push.sh | 4 ++--
t/t5521-pull-options.sh | 4 ++--
t/t5547-push-quarantine.sh | 4 ++--
t/t5548-push-porcelain.sh | 2 +-
t/t6500-gc.sh | 4 ++--
t/test-lib-functions.sh | 26 ++++++++++++++++++++++++++
11 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
index 6c941027a81..4532c90274b 100755
--- a/t/t1416-ref-transaction-hooks.sh
+++ b/t/t1416-ref-transaction-hooks.sh
@@ -18,7 +18,7 @@ test_expect_success setup '
test_expect_success 'hook allows updating ref if successful' '
test_when_finished "rm .git/hooks/reference-transaction" &&
git reset --hard PRE &&
- write_script .git/hooks/reference-transaction <<-\EOF &&
+ write_hook reference-transaction <<-\EOF &&
echo "$*" >>actual
EOF
cat >expect <<-EOF &&
@@ -32,7 +32,7 @@ test_expect_success 'hook allows updating ref if successful' '
test_expect_success 'hook aborts updating ref in prepared state' '
test_when_finished "rm .git/hooks/reference-transaction" &&
git reset --hard PRE &&
- write_script .git/hooks/reference-transaction <<-\EOF &&
+ write_hook reference-transaction <<-\EOF &&
if test "$1" = prepared
then
exit 1
@@ -45,7 +45,7 @@ test_expect_success 'hook aborts updating ref in prepared state' '
test_expect_success 'hook gets all queued updates in prepared state' '
test_when_finished "rm .git/hooks/reference-transaction actual" &&
git reset --hard PRE &&
- write_script .git/hooks/reference-transaction <<-\EOF &&
+ write_hook reference-transaction <<-\EOF &&
if test "$1" = prepared
then
while read -r line
@@ -68,7 +68,7 @@ test_expect_success 'hook gets all queued updates in prepared state' '
test_expect_success 'hook gets all queued updates in committed state' '
test_when_finished "rm .git/hooks/reference-transaction actual" &&
git reset --hard PRE &&
- write_script .git/hooks/reference-transaction <<-\EOF &&
+ write_hook reference-transaction <<-\EOF &&
if test "$1" = committed
then
while read -r line
@@ -88,7 +88,7 @@ test_expect_success 'hook gets all queued updates in committed state' '
test_expect_success 'hook gets all queued updates in aborted state' '
test_when_finished "rm .git/hooks/reference-transaction actual" &&
git reset --hard PRE &&
- write_script .git/hooks/reference-transaction <<-\EOF &&
+ write_hook reference-transaction <<-\EOF &&
if test "$1" = aborted
then
while read -r line
@@ -115,11 +115,11 @@ test_expect_success 'interleaving hook calls succeed' '
git init --bare target-repo.git &&
- write_script target-repo.git/hooks/reference-transaction <<-\EOF &&
+ write_hook -C target-repo.git reference-transaction <<-\EOF &&
echo $0 "$@" >>actual
EOF
- write_script target-repo.git/hooks/update <<-\EOF &&
+ write_hook -C target-repo.git update <<-\EOF &&
echo $0 "$@" >>actual
EOF
diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index 5c509db6fc3..c49aeea272c 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,7 @@ test_description='remote push rejects are reported by client'
. ./test-lib.sh
test_expect_success 'setup' '
- write_script .git/hooks/update <<-\EOF &&
+ write_hook update <<-\EOF &&
exit 1
EOF
echo 1 >file &&
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 9f1a483f426..1f7cad31442 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,7 @@ test_description='remote messages are colorized on the client'
. ./test-lib.sh
test_expect_success 'setup' '
- write_script .git/hooks/update <<-\EOF &&
+ write_hook update <<-\EOF &&
echo error: error
echo ERROR: also highlighted
echo hint: hint
diff --git a/t/t5411-proc-receive-hook.sh b/t/t5411-proc-receive-hook.sh
index 98b0e812082..054f4b2efb3 100755
--- a/t/t5411-proc-receive-hook.sh
+++ b/t/t5411-proc-receive-hook.sh
@@ -36,7 +36,7 @@ setup_upstream_and_workbench () {
TAG=$(git -C workbench rev-parse v123) &&
# setup pre-receive hook
- write_script upstream.git/hooks/pre-receive <<-\EOF &&
+ write_hook -C upstream.git pre-receive <<-\EOF &&
exec >&2
echo "# pre-receive hook"
while read old new ref
@@ -46,7 +46,7 @@ setup_upstream_and_workbench () {
EOF
# setup post-receive hook
- write_script upstream.git/hooks/post-receive <<-\EOF &&
+ write_hook -C upstream.git post-receive <<-\EOF &&
exec >&2
echo "# post-receive hook"
while read old new ref
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index a0faf0dd949..cdce39e6c76 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -265,7 +265,7 @@ test_expect_success 'fetch --atomic executes a single reference transaction only
EOF
rm -f atomic/actual &&
- write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
+ write_hook -C atomic reference-transaction <<-\EOF &&
( echo "$*" && cat ) >>actual
EOF
@@ -298,7 +298,7 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts'
EOF
rm -f atomic/actual &&
- write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
+ write_hook -C atomic/.git reference-transaction <<-\EOF &&
( echo "$*" && cat ) >>actual
exit 1
EOF
@@ -326,7 +326,7 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
test_line_count = 2 atomic/.git/FETCH_HEAD &&
cp atomic/.git/FETCH_HEAD expected &&
- write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
+ write_hook -C atomic reference-transaction <<-\EOF &&
exit 1
EOF
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index eea191d042f..11458052cb4 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1680,7 +1680,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' '
git reset --hard HEAD^^ &&
git tag initial &&
git config receive.denyCurrentBranch updateInstead &&
- write_script .git/hooks/push-to-checkout <<-\EOF
+ write_hook push-to-checkout <<-\EOF
echo >&2 updating from $(git rev-parse HEAD)
echo >&2 updating to "$1"
@@ -1739,7 +1739,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' '
(
cd void &&
git config receive.denyCurrentBranch updateInstead &&
- write_script .git/hooks/push-to-checkout <<-\EOF
+ write_hook push-to-checkout <<-\EOF
if git rev-parse --quiet --verify HEAD
then
has_head=yes
diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
index 66cfcb09c55..9b30e90383c 100755
--- a/t/t5521-pull-options.sh
+++ b/t/t5521-pull-options.sh
@@ -233,7 +233,7 @@ test_expect_success 'git pull --no-verify flag passed to merge' '
git init src &&
test_commit -C src one &&
git clone src dst &&
- write_script dst/.git/hooks/commit-msg <<-\EOF &&
+ write_hook -C dst commit-msg <<-\EOF &&
false
EOF
test_commit -C src two &&
@@ -245,7 +245,7 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '
git init src &&
test_commit -C src one &&
git clone src dst &&
- write_script dst/.git/hooks/commit-msg <<-\EOF &&
+ write_hook -C dst commit-msg <<-\EOF &&
false
EOF
test_commit -C src two &&
diff --git a/t/t5547-push-quarantine.sh b/t/t5547-push-quarantine.sh
index faaa51ccc56..e0bd469b110 100755
--- a/t/t5547-push-quarantine.sh
+++ b/t/t5547-push-quarantine.sh
@@ -5,7 +5,7 @@ test_description='check quarantine of objects during push'
test_expect_success 'create picky dest repo' '
git init --bare dest.git &&
- write_script dest.git/hooks/pre-receive <<-\EOF
+ write_hook -C dest.git pre-receive <<-\EOF
while read old new ref; do
test "$(git log -1 --format=%s $new)" = reject && exit 1
done
@@ -60,7 +60,7 @@ test_expect_success 'push to repo path with path separator (colon)' '
test_expect_success 'updating a ref from quarantine is forbidden' '
git init --bare update.git &&
- write_script update.git/hooks/pre-receive <<-\EOF &&
+ write_hook -C update.git pre-receive <<-\EOF &&
read old new refname
git update-ref refs/heads/unrelated $new
exit 1
diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh
index f11ff57e549..8997433a992 100755
--- a/t/t5548-push-porcelain.sh
+++ b/t/t5548-push-porcelain.sh
@@ -168,7 +168,7 @@ run_git_push_porcelain_output_test() {
'
test_expect_success "prepare pre-receive hook ($PROTOCOL)" '
- write_script "$upstream/hooks/pre-receive" <<-EOF
+ write_hook -C "$upstream" pre-receive <<-EOF
exit 1
EOF
'
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index c2021267f2c..98cf395806b 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -103,7 +103,7 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' '
git init pre-auto-gc-hook &&
(
cd pre-auto-gc-hook &&
- write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
+ write_hook pre-auto-gc <<-\EOF &&
echo >&2 no gc for you &&
exit 1
EOF
@@ -130,7 +130,7 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' '
(
cd pre-auto-gc-hook &&
- write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
+ write_hook pre-auto-gc <<-\EOF &&
echo >&2 will gc for you &&
exit 0
EOF
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index eef2262a360..3786d39ccab 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -551,6 +551,32 @@ write_script () {
chmod +x "$1"
}
+## Usage: write-hook pre-receive
+## Usage: write-hook -C some-dir pre-receive
+write_hook () {
+ indir= &&
+ while test $# != 0
+ do
+ case "$1" in
+ -C)
+ indir="$2"
+ shift
+ ;;
+ -*)
+ BUG "invalid write_hook: $1"
+ ;;
+ *)
+ break
+ ;;
+ esac &&
+ shift
+ done &&
+ git_dir=$(git -C "$indir" rev-parse --absolute-git-dir) &&
+ hook_dir="$git_dir/hooks" &&
+ hook_file="$hook_dir/$1"
+ write_script "$hook_file"
+}
+
# Use test_set_prereq to tell that a particular prerequisite is available.
# The prerequisite can later be checked for in two ways:
#
--
2.34.1.1020.gb1392dd1877
next prev parent reply other threads:[~2021-12-12 20:15 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-12 20:13 [PATCH 00/13] tests + init: don't rely on templates & add --no-template + config Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 01/13] t0001: fix gaps in "TEMPLATE DIRECTORY" coverage Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 02/13] init: split out template population from create_default_files() Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 03/13] init: unconditionally create the "info" directory Ævar Arnfjörð Bjarmason
2021-12-20 15:59 ` Derrick Stolee
2021-12-20 16:13 ` Ævar Arnfjörð Bjarmason
2021-12-20 17:39 ` Derrick Stolee
2021-12-20 18:16 ` Ævar Arnfjörð Bjarmason
2021-12-20 19:06 ` Junio C Hamano
2021-12-21 1:15 ` Ævar Arnfjörð Bjarmason
2021-12-21 2:10 ` Junio C Hamano
2021-12-21 2:39 ` Ævar Arnfjörð Bjarmason
2021-12-21 6:38 ` Junio C Hamano
2021-12-24 17:26 ` Ævar Arnfjörð Bjarmason
2021-12-25 1:58 ` Junio C Hamano
2022-01-12 12:42 ` Ævar Arnfjörð Bjarmason
2022-01-18 19:43 ` Derrick Stolee
2022-01-19 1:00 ` Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 04/13] t0008: don't rely on default ".git/info/exclude" Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 05/13] init & clone: add a --no-template option Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 06/13] init & clone: add init.templateDir=[bool] Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 07/13] test-lib: create test data with "git init --no-template" (almost) Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 08/13] tests: don't depend on template-created .git/branches Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 09/13] t5540: don't rely on "hook/post-update.sample" Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` Ævar Arnfjörð Bjarmason [this message]
2021-12-13 14:15 ` [PATCH 10/13] test-lib-functions: add and use a "write_hook" wrapper Eric Sunshine
2021-12-13 16:29 ` Ævar Arnfjörð Bjarmason
2021-12-13 16:45 ` Eric Sunshine
2021-12-13 19:37 ` Ævar Arnfjörð Bjarmason
2021-12-13 21:33 ` Eric Sunshine
2021-12-12 20:13 ` [PATCH 11/13] tests: change "cat && chmod +x" to use "write_hook" Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 12/13] tests: migrate miscellaneous "write_script" to "write_hooks" Ævar Arnfjörð Bjarmason
2021-12-12 20:13 ` [PATCH 13/13] tests: don't depend on template-created .git/hooks Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 0/7] tests: don't depend on "git init" using the template Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 1/7] t0008: don't rely on default ".git/info/exclude" Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 2/7] tests: don't depend on template-created .git/branches Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 3/7] tests: don't assume a .git/info for .git/info/grafts Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 4/7] tests: don't assume a .git/info for .git/info/attributes Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 5/7] tests: don't assume a .git/info for .git/info/refs Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 6/7] tests: don't assume a .git/info for .git/info/exclude Ævar Arnfjörð Bjarmason
2022-06-03 11:15 ` [PATCH v2 7/7] tests: don't assume a .git/info for .git/info/sparse-checkout Ævar Arnfjörð Bjarmason
2022-06-03 19:17 ` [PATCH v2 0/7] tests: don't depend on "git init" using the template Junio C Hamano
2022-06-04 0:41 ` Ævar Arnfjörð Bjarmason
2022-06-06 19:08 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-10.13-ca55471d134-20211212T201308Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=derrickstolee@github.com \
--cc=git@adamspiers.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).