1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

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
This commit is contained in:
epriestley 2011-12-26 09:17:50 -08:00
parent aba5b48202
commit abd8efc358
2 changed files with 24 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -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) {