Path: blob/master/src/applications/diffusion/protocol/DiffusionGitCommandEngine.php
12242 views
<?php12final class DiffusionGitCommandEngine3extends DiffusionCommandEngine {45protected function canBuildForRepository(6PhabricatorRepository $repository) {7return $repository->isGit();8}910protected function newFormattedCommand($pattern, array $argv) {11$pattern = "git {$pattern}";12return array($pattern, $argv);13}1415protected function shouldAlwaysSudo() {1617// See T13673. In Git, always try to use "sudo" to execute commands as the18// daemon user (if such a user is configured), because Git 2.35.2 and newer19// (and some older versions of Git with backported security patches) refuse20// to execute if the top level repository directory is not owned by the21// current user.2223// Previously, we used "sudo" only when performing writes to the24// repository directory.2526return true;27}2829protected function newCustomEnvironment() {30$env = array();3132// NOTE: See T2965. Some time after Git 1.7.5.4, Git started fataling if33// it can not read $HOME. For many users, $HOME points at /root (this34// seems to be a default result of Apache setup). Instead, explicitly35// point $HOME at a readable, empty directory so that Git looks for the36// config file it's after, fails to locate it, and moves on. This is37// really silly, but seems like the least damaging approach to38// mitigating the issue.3940$env['HOME'] = PhabricatorEnv::getEmptyCWD();4142$env['GIT_SSH'] = $this->getSSHWrapper();43$env['GIT_SSH_VARIANT'] = 'ssh';4445if ($this->isAnyHTTPProtocol()) {46$uri = $this->getURI();47if ($uri) {48$proxy = PhutilHTTPEngineExtension::buildHTTPProxyURI($uri);49if ($proxy) {50if ($this->isHTTPSProtocol()) {51$env_key = 'https_proxy';52} else {53$env_key = 'http_proxy';54}55$env[$env_key] = (string)$proxy;56}57}58}5960return $env;61}6263}646566