From abd8efc35855c2a1b36928fde7eeab24be87b4d9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 26 Dec 2011 09:17:50 -0800 Subject: [PATCH] Further relax same origin checks Summary: Allow paths to match even if they differ by trailing slashes and ".git". Test Plan: Ran unit tests. Reviewers: jungejason, btrahan Reviewed By: jungejason CC: aran, jungejason Maniphest Tasks: T710 Differential Revision: https://secure.phabricator.com/D1286 --- ...habricatorRepositoryGitCommitDiscoveryDaemon.php | 13 ++++++++++++- ...orRepositoryGitCommitDiscoveryDaemonTestCase.php | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/applications/repository/daemon/commitdiscovery/git/PhabricatorRepositoryGitCommitDiscoveryDaemon.php b/src/applications/repository/daemon/commitdiscovery/git/PhabricatorRepositoryGitCommitDiscoveryDaemon.php index 3fffe8d4e3..359443b568 100644 --- a/src/applications/repository/daemon/commitdiscovery/git/PhabricatorRepositoryGitCommitDiscoveryDaemon.php +++ b/src/applications/repository/daemon/commitdiscovery/git/PhabricatorRepositoryGitCommitDiscoveryDaemon.php @@ -121,7 +121,10 @@ class PhabricatorRepositoryGitCommitDiscoveryDaemon $remote_path = $remote_uri->getPath(); $expect_path = $expect_uri->getPath(); - if ($remote_path != $expect_path) { + $remote_match = self::normalizeGitPath($remote_path); + $expect_match = self::normalizeGitPath($expect_path); + + if ($remote_match != $expect_match) { throw new Exception( "Working copy at '{$where}' has a mismatched origin URL. It has ". "origin URL '{$remote}' (with remote path '{$remote_path}'), but the ". @@ -131,4 +134,12 @@ class PhabricatorRepositoryGitCommitDiscoveryDaemon } } + private static function normalizeGitPath($path) { + // Strip away trailing "/" and ".git", so similar paths correctly match. + + $path = rtrim($path, '/'); + $path = preg_replace('/\.git$/', '', $path); + return $path; + } + } diff --git a/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php b/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php index 0c31c4462e..8ba7af1d1b 100644 --- a/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php +++ b/src/applications/repository/daemon/commitdiscovery/git/__tests__/PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase.php @@ -63,6 +63,18 @@ final class PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase false, 'Git implicit SSH path changes should fail.', ), + array( + 'user@domain.com:path/repo.git', + 'user@domain.com:path/repo', + true, + 'Optional .git extension should not prevent matches.', + ), + array( + 'user@domain.com:path/repo/', + 'user@domain.com:path/repo', + true, + 'Optional trailing slash should not prevent matches.', + ), ); foreach ($cases as $case) {