mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
aba5b48202
commit
abd8efc358
2 changed files with 24 additions and 1 deletions
|
@ -121,7 +121,10 @@ class PhabricatorRepositoryGitCommitDiscoveryDaemon
|
||||||
$remote_path = $remote_uri->getPath();
|
$remote_path = $remote_uri->getPath();
|
||||||
$expect_path = $expect_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(
|
throw new Exception(
|
||||||
"Working copy at '{$where}' has a mismatched origin URL. It has ".
|
"Working copy at '{$where}' has a mismatched origin URL. It has ".
|
||||||
"origin URL '{$remote}' (with remote path '{$remote_path}'), but the ".
|
"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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,18 @@ final class PhabricatorRepositoryGitCommitDiscoveryDaemonTestCase
|
||||||
false,
|
false,
|
||||||
'Git implicit SSH path changes should fail.',
|
'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) {
|
foreach ($cases as $case) {
|
||||||
|
|
Loading…
Reference in a new issue