diff --git a/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php b/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php index 8ba7af1d1b..1bef77e5c1 100644 --- a/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php +++ b/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php @@ -1,7 +1,7 @@ getProtocol()) { - list($domain, $path) = explode(':', $raw_uri, 2); - $uri = new PhutilURI('ssh://'.$domain.'/'.$path); + if (strpos($raw_uri, '/') === 0) { + // If the URI starts with a '/', it's an implicit file:// URI on the + // local disk. + $uri = new PhutilURI('file://'.$raw_uri); + } else if (strpos($raw_uri, ':') !== false) { + // If there's no protocol (git implicit SSH) but the URI has a colon, + // it's a git implicit SSH URI. Reformat the URI to be a normal URI. + // These git URIs look like "user@domain.com:path" instead of + // "ssh://user@domain/path". + list($domain, $path) = explode(':', $raw_uri, 2); + $uri = new PhutilURI('ssh://'.$domain.'/'.$path); + } else { + throw new Exception("The Git URI '{$raw_uri}' could not be parsed."); + } } return $uri; diff --git a/src/applications/repository/storage/repository/__tests__/PhabricatorRepositoryTestCase.php b/src/applications/repository/storage/repository/__tests__/PhabricatorRepositoryTestCase.php index 7af6246422..eb5d178d26 100644 --- a/src/applications/repository/storage/repository/__tests__/PhabricatorRepositoryTestCase.php +++ b/src/applications/repository/storage/repository/__tests__/PhabricatorRepositoryTestCase.php @@ -23,6 +23,7 @@ final class PhabricatorRepositoryTestCase static $map = array( 'ssh://user@domain.com/path.git' => 'ssh://user@domain.com/path.git', 'user@domain.com:path.git' => 'ssh://user@domain.com/path.git', + '/path/to/local/repo.git' => 'file:///path/to/local/repo.git', ); foreach ($map as $raw => $expect) { @@ -34,6 +35,25 @@ final class PhabricatorRepositoryTestCase } } + public function testParseBadGitURI() { + $junk = array( + 'herp derp moon balloon', + ); + + foreach ($junk as $garbage) { + $ex = null; + try { + $uri = PhabricatorRepository::newPhutilURIFromGitURI($garbage); + } catch (Exception $caught) { + $ex = $caught; + } + $this->assertEqual( + true, + (bool)$ex, + 'Expect exception when parsing garbage.'); + } + } + public function testBranchFilter() { $git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;