mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +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:
parent
88fec4908b
commit
c48f64b391
2 changed files with 27 additions and 4 deletions
|
@ -159,6 +159,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
$pattern = $args[0];
|
||||
$args = array_slice($args, 1);
|
||||
|
||||
$empty = $this->getEmptyReadableDirectoryPath();
|
||||
|
||||
if ($this->shouldUseSSH()) {
|
||||
switch ($this->getVersionControlSystem()) {
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||
|
@ -175,8 +177,9 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
'csprintf',
|
||||
array_merge(
|
||||
array(
|
||||
"(ssh-add %s && git {$pattern})",
|
||||
"(ssh-add %s && HOME=%s git {$pattern})",
|
||||
$this->getSSHKeyfile(),
|
||||
$empty,
|
||||
),
|
||||
$args));
|
||||
$pattern = "ssh-agent sh -c %s";
|
||||
|
@ -239,7 +242,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
$pattern = "svn --non-interactive {$pattern}";
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||
$pattern = "git {$pattern}";
|
||||
$pattern = "HOME=%s git {$pattern}";
|
||||
array_unshift($args, $empty);
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||
$pattern = "hg {$pattern}";
|
||||
|
@ -258,14 +262,16 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
$pattern = $args[0];
|
||||
$args = array_slice($args, 1);
|
||||
|
||||
$empty = $this->getEmptyReadableDirectoryPath();
|
||||
|
||||
switch ($this->getVersionControlSystem()) {
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||
$pattern = "(cd %s && svn --non-interactive {$pattern})";
|
||||
array_unshift($args, $this->getLocalPath());
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||
$pattern = "(cd %s && git {$pattern})";
|
||||
array_unshift($args, $this->getLocalPath());
|
||||
$pattern = "(cd %s && HOME=%s git {$pattern})";
|
||||
array_unshift($args, $this->getLocalPath(), $empty);
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||
$hgplain = (phutil_is_windows() ? "set HGPLAIN=1 &&" : "HGPLAIN=1");
|
||||
|
@ -281,6 +287,17 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
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() {
|
||||
return $this->getDetail('ssh-login');
|
||||
}
|
||||
|
|
6
support/empty/README
Normal file
6
support/empty/README
Normal 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.
|
||||
|
Loading…
Reference in a new issue