mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Pass GIT_ENVIRONMENTAL_MAGIC through to hook subprocesses to support Git 2.11.0
Summary: Fixes T11940. In 2.11.0, Git has made a change so that newly-pushed changes are held in a temporary area until the hook accepts or rejects them. This magic temporary area is only readable if the appropriate `GIT_ENVIRONMENTAL_MAGIC` variables are available. When executing `git` commands, pass them through from the calling context. We're intentionally conservative about which variables we pass, and with good reason (see "httpoxy" in T11359). I think this continues to be the correct default behavior. Test Plan: - Upgraded to Git 2.11.0. - Tried to push over SSH, got a hook error. - Applied patch. - Pulled and pushed over SSH. - Pulled and pushed over HTTP. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11940 Differential Revision: https://secure.phabricator.com/D16988
This commit is contained in:
parent
6058d3305f
commit
005d8493b0
3 changed files with 58 additions and 1 deletions
|
@ -610,7 +610,11 @@ final class DiffusionCommitHookEngine extends Phobject {
|
|||
self::ENV_REMOTE_ADDRESS => $this->getRemoteAddress(),
|
||||
);
|
||||
|
||||
$directories = $this->getRepository()->getHookDirectories();
|
||||
$repository = $this->getRepository();
|
||||
|
||||
$env += $repository->getPassthroughEnvironmentalVariables();
|
||||
|
||||
$directories = $repository->getHookDirectories();
|
||||
foreach ($directories as $directory) {
|
||||
$hooks = $this->getExecutablesInDirectory($directory);
|
||||
sort($hooks);
|
||||
|
|
|
@ -209,6 +209,8 @@ abstract class DiffusionCommandEngine extends Phobject {
|
|||
}
|
||||
}
|
||||
|
||||
$env += $repository->getPassthroughEnvironmentalVariables();
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
|
|
|
@ -2015,6 +2015,57 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
return $client;
|
||||
}
|
||||
|
||||
public function getPassthroughEnvironmentalVariables() {
|
||||
$env = $_ENV;
|
||||
|
||||
if ($this->isGit()) {
|
||||
// $_ENV does not populate in CLI contexts if "E" is missing from
|
||||
// "variables_order" in PHP config. Currently, we do not require this
|
||||
// to be configured. Since it may not be, explictitly bring expected Git
|
||||
// environmental variables into scope. This list is not exhaustive, but
|
||||
// only lists variables with a known impact on commit hook behavior.
|
||||
|
||||
// This can be removed if we later require "E" in "variables_order".
|
||||
|
||||
$git_env = array(
|
||||
'GIT_OBJECT_DIRECTORY',
|
||||
'GIT_ALTERNATE_OBJECT_DIRECTORIES',
|
||||
'GIT_QUARANTINE_PATH',
|
||||
);
|
||||
foreach ($git_env as $key) {
|
||||
$value = getenv($key);
|
||||
if (strlen($value)) {
|
||||
$env[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$key = 'GIT_PUSH_OPTION_COUNT';
|
||||
$git_count = getenv($key);
|
||||
if (strlen($git_count)) {
|
||||
$git_count = (int)$git_count;
|
||||
$env[$key] = $git_count;
|
||||
for ($ii = 0; $ii < $git_count; $ii++) {
|
||||
$key = 'GIT_PUSH_OPTION_'.$ii;
|
||||
$env[$key] = getenv($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($env as $key => $value) {
|
||||
// In Git, pass anything matching "GIT_*" though. Some of these variables
|
||||
// need to be preserved to allow `git` operations to work properly when
|
||||
// running from commit hooks.
|
||||
if ($this->isGit()) {
|
||||
if (preg_match('/^GIT_/', $key)) {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* -( Repository URIs )---------------------------------------------------- */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue