Skip to content

Commit 0856f13

Browse files
pks-tgitster
authored andcommitted
t9164: fix inability to find basename(1) in Subversion hooks
Hooks executed by Subversion are spawned with an empty environment. By default, not even variables like PATH will be propagated to them. In order to ensure that we're still able to find required executables, we thus write the current PATH variable into the hook script itself and then re-export it in t9164. This happens too late in the script though, as we already tried to execute the basename(1) utility before exporting the PATH variable. This tends to work on most platforms as the fallback value of PATH for Bash (see `getconf PATH`) is likely to contain this binary. But on more exotic platforms like NixOS this is not the case, and thus the test fails. While we could work around this issue by simply setting PATH earlier, it feels fragile to inject a user-controlled value into the script and have the shell interpret it. Instead, we can refactor the hook setup to write a `hooks-env` file that configures PATH for us. Like this, Subversion will know to set up the environment as expected for all hooks. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d70afa commit 0856f13

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

t/t9164-git-svn-dcommit-concurrent.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ setup_hook()
4646
"passed to setup_hook" >&2 ; return 1; }
4747
echo "cnt=$skip_revs" > "$hook_type-counter"
4848
rm -f "$rawsvnrepo/hooks/"*-commit # drop previous hooks
49+
50+
# Subversion hooks run with an empty environment by default. We thus
51+
# need to propagate PATH so that we can find executables.
52+
cat >"$rawsvnrepo/conf/hooks-env" <<-EOF
53+
[default]
54+
PATH = ${PATH}
55+
EOF
56+
4957
hook="$rawsvnrepo/hooks/$hook_type"
5058
cat > "$hook" <<- 'EOF1'
5159
#!/bin/sh
@@ -63,7 +71,6 @@ EOF1
6371
if [ "$hook_type" = "pre-commit" ]; then
6472
echo "echo 'commit disallowed' >&2; exit 1" >>"$hook"
6573
else
66-
echo "PATH=\"$PATH\"; export PATH" >>"$hook"
6774
echo "svnconf=\"$svnconf\"" >>"$hook"
6875
cat >>"$hook" <<- 'EOF2'
6976
cd work-auto-commits.svn

0 commit comments

Comments
 (0)