Re: [PATCH 10/13] test-lib-functions: add and use a "write_hook" wrapper
From: Eric Sunshine <hidden>
Date: 2021-12-13 14:16:11
On Sun, Dec 12, 2021 at 4:24 PM Ævar Arnfjörð Bjarmason [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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. [...] Signed-off-by: Ævar Arnfjörð Bjarmason <redacted> ---diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh@@ -551,6 +551,32 @@ write_script () { +## Usage: write-hook pre-receive +## Usage: write-hook -C some-dir pre-receive +write_hook () { + indir= && + while test $# != 0 + do
It's not clear whether the intention is to maintain the &&-chain in this function...
+ case "$1" in + -C) + indir="$2" + shift + ;;
... or not care about it since it's broken here before `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"
... and here before `write_script`.
+}