From b10fa8023f370d1c9ea5cc3f8cda60c4707269d2 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 11 Jan 2012 08:38:21 -0800 Subject: [PATCH] Support Git implicit file:// URIs Summary: @s reported an issue with implicit file:// URIs in Git, see P270. Recognize and handle URIs in this format. For URIs we don't understand, raise an exception. Test Plan: - Added failing tests. - Fixed code. - Tests pass. Reviewers: btrahan, jungejason, s Reviewed By: s CC: aran, epriestley, s Differential Revision: https://secure.phabricator.com/D1362 --- ...sitoryGitCommitDiscoveryDaemonTestCase.php | 14 ++++++++++++- .../repository/PhabricatorRepository.php | 20 +++++++++++++------ .../PhabricatorRepositoryTestCase.php | 20 +++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) 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;