@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+58 -1
+5 -1
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 610 610 self::ENV_REMOTE_ADDRESS => $this->getRemoteAddress(), 611 611 ); 612 612 613 - $directories = $this->getRepository()->getHookDirectories(); 613 + $repository = $this->getRepository(); 614 + 615 + $env += $repository->getPassthroughEnvironmentalVariables(); 616 + 617 + $directories = $repository->getHookDirectories(); 614 618 foreach ($directories as $directory) { 615 619 $hooks = $this->getExecutablesInDirectory($directory); 616 620 sort($hooks);
+2
src/applications/diffusion/protocol/DiffusionCommandEngine.php
··· 209 209 } 210 210 } 211 211 212 + $env += $repository->getPassthroughEnvironmentalVariables(); 213 + 212 214 return $env; 213 215 } 214 216
+51
src/applications/repository/storage/PhabricatorRepository.php
··· 2015 2015 return $client; 2016 2016 } 2017 2017 2018 + public function getPassthroughEnvironmentalVariables() { 2019 + $env = $_ENV; 2020 + 2021 + if ($this->isGit()) { 2022 + // $_ENV does not populate in CLI contexts if "E" is missing from 2023 + // "variables_order" in PHP config. Currently, we do not require this 2024 + // to be configured. Since it may not be, explictitly bring expected Git 2025 + // environmental variables into scope. This list is not exhaustive, but 2026 + // only lists variables with a known impact on commit hook behavior. 2027 + 2028 + // This can be removed if we later require "E" in "variables_order". 2029 + 2030 + $git_env = array( 2031 + 'GIT_OBJECT_DIRECTORY', 2032 + 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 2033 + 'GIT_QUARANTINE_PATH', 2034 + ); 2035 + foreach ($git_env as $key) { 2036 + $value = getenv($key); 2037 + if (strlen($value)) { 2038 + $env[$key] = $value; 2039 + } 2040 + } 2041 + 2042 + $key = 'GIT_PUSH_OPTION_COUNT'; 2043 + $git_count = getenv($key); 2044 + if (strlen($git_count)) { 2045 + $git_count = (int)$git_count; 2046 + $env[$key] = $git_count; 2047 + for ($ii = 0; $ii < $git_count; $ii++) { 2048 + $key = 'GIT_PUSH_OPTION_'.$ii; 2049 + $env[$key] = getenv($key); 2050 + } 2051 + } 2052 + } 2053 + 2054 + $result = array(); 2055 + foreach ($env as $key => $value) { 2056 + // In Git, pass anything matching "GIT_*" though. Some of these variables 2057 + // need to be preserved to allow `git` operations to work properly when 2058 + // running from commit hooks. 2059 + if ($this->isGit()) { 2060 + if (preg_match('/^GIT_/', $key)) { 2061 + $result[$key] = $value; 2062 + } 2063 + } 2064 + } 2065 + 2066 + return $result; 2067 + } 2068 + 2018 2069 /* -( Repository URIs )---------------------------------------------------- */ 2019 2070 2020 2071