Changeset View
Changeset View
Standalone View
Standalone View
src/repository/api/ArcanistGitAPI.php
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | public function execPassthru($pattern /* , ... */) { | ||||
| return call_user_func_array('phutil_passthru', $args); | return call_user_func_array('phutil_passthru', $args); | ||||
| } | } | ||||
| public function getSourceControlSystemName() { | public function getSourceControlSystemName() { | ||||
| return 'git'; | return 'git'; | ||||
| } | } | ||||
| public function getGitVersion() { | |||||
| list($stdout) = $this->execxLocal('--version'); | |||||
| return rtrim(str_replace('git version ', '', $stdout)); | |||||
| } | |||||
| public function getMetadataPath() { | public function getMetadataPath() { | ||||
| static $path = null; | static $path = null; | ||||
| if ($path === null) { | if ($path === null) { | ||||
| list($stdout) = $this->execxLocal('rev-parse --git-dir'); | list($stdout) = $this->execxLocal('rev-parse --git-dir'); | ||||
| $path = rtrim($stdout, "\n"); | $path = rtrim($stdout, "\n"); | ||||
| // the output of git rev-parse --git-dir is an absolute path, unless | // the output of git rev-parse --git-dir is an absolute path, unless | ||||
| // the cwd is the root of the repository, in which case it uses the | // the cwd is the root of the repository, in which case it uses the | ||||
| // relative path of .git. If we get this relative path, turn it into | // relative path of .git. If we get this relative path, turn it into | ||||
| ▲ Show 20 Lines • Show All 449 Lines • ▼ Show 20 Lines | if ($err === 0) { | ||||
| return null; | return null; | ||||
| } else { | } else { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht('Command %s failed: %s', 'git symbolic-ref', $stderr)); | pht('Command %s failed: %s', 'git symbolic-ref', $stderr)); | ||||
| } | } | ||||
| } | } | ||||
| public function getRemoteURI() { | public function getRemoteURI() { | ||||
| // "git ls-remote --get-url" is the appropriate plumbing to get the remote | |||||
| // URI. "git config remote.origin.url", on the other hand, may not be as | |||||
| // accurate (for example, it does not take into account possible URL | |||||
| // rewriting rules set by the user through "url.<base>.insteadOf"). However, | |||||
| // the --get-url flag requires git 1.7.5. | |||||
| $version = $this->getGitVersion(); | |||||
| if (version_compare($version, '1.7.5', '>=')) { | |||||
| list($stdout) = $this->execxLocal('ls-remote --get-url origin'); | list($stdout) = $this->execxLocal('ls-remote --get-url origin'); | ||||
| } else { | |||||
| list($stdout) = $this->execxLocal('config remote.origin.url'); | |||||
| } | |||||
| $uri = rtrim($stdout); | $uri = rtrim($stdout); | ||||
| if ($uri === 'origin') { | // 'origin' is what ls-remote outputs if no origin remote URI exists | ||||
| if (!$uri || $uri === 'origin') { | |||||
| return null; | return null; | ||||
| } | } | ||||
| return $uri; | return $uri; | ||||
| } | } | ||||
| public function getSourceControlPath() { | public function getSourceControlPath() { | ||||
| // TODO: Try to get something useful here. | // TODO: Try to get something useful here. | ||||
| ▲ Show 20 Lines • Show All 756 Lines • Show Last 20 Lines | |||||