Skip to content

Hooks run with an empty environment except GIT_DIR and GIT_WORK_TREE #13

Closed

Description

@dnnsjsk

HookRunner::run() starts the hook with an environment that contains only GIT_DIR and GIT_WORK_TREE (

$env = [
'GIT_DIR' => $this->gitDir,
'GIT_WORK_TREE' => dirname($this->gitDir),
];
$process = proc_open($command, $descriptors, $pipes, dirname($this->gitDir), $env);
). Passing an $env array to proc_open() replaces the environment, so PATH, HOME, USER, LANG, SSH_AUTH_SOCK and everything else from the PHP process are missing in the hook. git passes its own environment through and adds the GIT_* variables.

Repro

pitmaster init && git config user.name T && git config user.email t@x
printf '#!/bin/sh\necho "PATH=$PATH HOME=$HOME" > /tmp/hookenv.txt\n' > .git/hooks/post-commit
chmod +x .git/hooks/post-commit
echo a > a.txt && pitmaster add a.txt && pitmaster commit -m first
cat /tmp/hookenv.txt
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=

(The PATH shown is the shell's built-in default because the variable is unset; HOME is empty.) Hooks that call tools from a user or project PATH (vendor/bin, node_modules/.bin, version managers) or rely on HOME fail or behave differently than under git.

Expected

The hook inherits the PHP process environment (getenv()) with GIT_DIR and GIT_WORK_TREE added or overridden.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions