@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
at upstream/main 64 lines 1.9 kB view raw
1<?php 2 3final class DiffusionGitCommandEngine 4 extends DiffusionCommandEngine { 5 6 protected function canBuildForRepository( 7 PhabricatorRepository $repository) { 8 return $repository->isGit(); 9 } 10 11 protected function newFormattedCommand($pattern, array $argv) { 12 $pattern = "git {$pattern}"; 13 return array($pattern, $argv); 14 } 15 16 protected function shouldAlwaysSudo() { 17 18 // See T13673. In Git, always try to use "sudo" to execute commands as the 19 // daemon user (if such a user is configured), because Git 2.35.2 and newer 20 // (and some older versions of Git with backported security patches) refuse 21 // to execute if the top level repository directory is not owned by the 22 // current user. 23 24 // Previously, we used "sudo" only when performing writes to the 25 // repository directory. 26 27 return true; 28 } 29 30 protected function newCustomEnvironment() { 31 $env = array(); 32 33 // NOTE: See T2965. Some time after Git 1.7.5.4, Git started fataling if 34 // it can not read $HOME. For many users, $HOME points at /root (this 35 // seems to be a default result of Apache setup). Instead, explicitly 36 // point $HOME at a readable, empty directory so that Git looks for the 37 // config file it's after, fails to locate it, and moves on. This is 38 // really silly, but seems like the least damaging approach to 39 // mitigating the issue. 40 41 $env['HOME'] = PhabricatorEnv::getEmptyCWD(); 42 43 $env['GIT_SSH'] = $this->getSSHWrapper(); 44 $env['GIT_SSH_VARIANT'] = 'ssh'; 45 46 if ($this->isAnyHTTPProtocol()) { 47 $uri = $this->getURI(); 48 if ($uri) { 49 $proxy = PhutilHTTPEngineExtension::buildHTTPProxyURI($uri); 50 if ($proxy) { 51 if ($this->isHTTPSProtocol()) { 52 $env_key = 'https_proxy'; 53 } else { 54 $env_key = 'http_proxy'; 55 } 56 $env[$env_key] = (string)$proxy; 57 } 58 } 59 } 60 61 return $env; 62 } 63 64}