Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
0856f13a 5d70afa5

+8 -1
+8 -1
t/t9164-git-svn-dcommit-concurrent.sh
··· 46 46 "passed to setup_hook" >&2 ; return 1; } 47 47 echo "cnt=$skip_revs" > "$hook_type-counter" 48 48 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 + 49 57 hook="$rawsvnrepo/hooks/$hook_type" 50 58 cat > "$hook" <<- 'EOF1' 51 59 #!/bin/sh ··· 63 71 if [ "$hook_type" = "pre-commit" ]; then 64 72 echo "echo 'commit disallowed' >&2; exit 1" >>"$hook" 65 73 else 66 - echo "PATH=\"$PATH\"; export PATH" >>"$hook" 67 74 echo "svnconf=\"$svnconf\"" >>"$hook" 68 75 cat >>"$hook" <<- 'EOF2' 69 76 cd work-auto-commits.svn