diff --git a/src/applications/config/controller/PhabricatorConfigConsoleController.php b/src/applications/config/controller/PhabricatorConfigConsoleController.php --- a/src/applications/config/controller/PhabricatorConfigConsoleController.php +++ b/src/applications/config/controller/PhabricatorConfigConsoleController.php @@ -150,6 +150,16 @@ $log_futures = array(); $remote_futures = array(); + // Git commands needs the HOME environment variable + // to read their .gitconfig - otherwise you cannot + // fix errors like "detected dubious ownership" + // https://we.phorge.it/T15282 + $commands_env = array(); + $webserver_home = self::webserverHomePath(); + if ($webserver_home) { + $commands_env['HOME'] = $webserver_home; + } + foreach ($specs as $lib) { $root = dirname(phutil_get_library_root($lib)); @@ -161,9 +171,11 @@ 'git remote -v'); $log_futures[$lib] = id(new ExecFuture('%C', $log_command)) + ->setEnv($commands_env) ->setCWD($root); $remote_futures[$lib] = id(new ExecFuture('%C', $remote_command)) + ->setEnv($commands_env) ->setCWD($root); } @@ -248,6 +260,7 @@ $root = dirname(phutil_get_library_root($lib)); $upstream_futures[$lib] = id(new ExecFuture('%C', $merge_base_command)) + ->setEnv($commands_env) ->setCWD($root); } @@ -340,5 +353,40 @@ ->appendChild($table_view); } + /** + * Get the HOME of the current webserver user + * + * Example: In mod_php it returns something like "/var/www/html" + * Example: In PHP-FPM it returns the home of the configured pool user + * + * @return string|null|false + */ + private static function webserverHomePath() { + + $home = null; + + // Almost surely Microsoft Windows does not have these functions + if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) { + + // This is almost surely Unix/Linux + + // Let's read the "effective" user UID (not the "real" one) + // Example: in PHP-FPM we want the effective pool user, not root daemon + // https://we.phorge.it/T15298 + $webserver_user = posix_getpwuid(posix_geteuid()); + if ($webserver_user !== false) { + $home = $webserver_user['dir']; + } + } else { + + // This is almost surely Microsoft Windows + + // Let's read this environment var + // if missing, it's just false + $home = getenv('USERPROFILE'); + } + + return $home; + } }