1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

Specify HOME when invoking Git commands

Summary: Fixes T2965, see that task for discussion. This is dumb but seems like our best bet.

Test Plan:
  - Installed newish version of Git.
  - Set HOME on the websever to `/var/root` (or any other unreadable directory).
  - Hit the error described in T2965 when viewing Diffusion.
  - Applied this patch.
  - Diffusion works.

Reviewers: btrahan, joel

Reviewed By: btrahan

CC: aran, chad

Maniphest Tasks: T2965

Differential Revision: https://secure.phabricator.com/D5994
This commit is contained in:
epriestley 2013-05-21 14:14:31 -07:00
parent 88fec4908b
commit c48f64b391
2 changed files with 27 additions and 4 deletions

View file

@ -159,6 +159,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$pattern = $args[0]; $pattern = $args[0];
$args = array_slice($args, 1); $args = array_slice($args, 1);
$empty = $this->getEmptyReadableDirectoryPath();
if ($this->shouldUseSSH()) { if ($this->shouldUseSSH()) {
switch ($this->getVersionControlSystem()) { switch ($this->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
@ -175,8 +177,9 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
'csprintf', 'csprintf',
array_merge( array_merge(
array( array(
"(ssh-add %s && git {$pattern})", "(ssh-add %s && HOME=%s git {$pattern})",
$this->getSSHKeyfile(), $this->getSSHKeyfile(),
$empty,
), ),
$args)); $args));
$pattern = "ssh-agent sh -c %s"; $pattern = "ssh-agent sh -c %s";
@ -239,7 +242,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$pattern = "svn --non-interactive {$pattern}"; $pattern = "svn --non-interactive {$pattern}";
break; break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$pattern = "git {$pattern}"; $pattern = "HOME=%s git {$pattern}";
array_unshift($args, $empty);
break; break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$pattern = "hg {$pattern}"; $pattern = "hg {$pattern}";
@ -258,14 +262,16 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$pattern = $args[0]; $pattern = $args[0];
$args = array_slice($args, 1); $args = array_slice($args, 1);
$empty = $this->getEmptyReadableDirectoryPath();
switch ($this->getVersionControlSystem()) { switch ($this->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$pattern = "(cd %s && svn --non-interactive {$pattern})"; $pattern = "(cd %s && svn --non-interactive {$pattern})";
array_unshift($args, $this->getLocalPath()); array_unshift($args, $this->getLocalPath());
break; break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$pattern = "(cd %s && git {$pattern})"; $pattern = "(cd %s && HOME=%s git {$pattern})";
array_unshift($args, $this->getLocalPath()); array_unshift($args, $this->getLocalPath(), $empty);
break; break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$hgplain = (phutil_is_windows() ? "set HGPLAIN=1 &&" : "HGPLAIN=1"); $hgplain = (phutil_is_windows() ? "set HGPLAIN=1 &&" : "HGPLAIN=1");
@ -281,6 +287,17 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
return $args; return $args;
} }
private function getEmptyReadableDirectoryPath() {
// See T2965. Some time after Git 1.7.5.4, Git started fataling if it can
// not read $HOME. For many users, $HOME points at /root (this seems to be
// a default result of Apache setup). Instead, explicitly point $HOME at a
// readable, empty directory so that Git looks for the config file it's
// after, fails to locate it, and moves on. This is really silly, but seems
// like the least damaging approach to mitigating the issue.
$root = dirname(phutil_get_library_root('phabricator'));
return $root.'/support/empty/';
}
private function getSSHLogin() { private function getSSHLogin() {
return $this->getDetail('ssh-login'); return $this->getDetail('ssh-login');
} }

6
support/empty/README Normal file
View file

@ -0,0 +1,6 @@
This is an empty, readable directory. If you need an empty, readable directory
for some reason, you can use this one.
Of course, it's not quite empty because it has this file in it. So it's a
mostly-empty, readable directory.