mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Add a safety check to commit discovery daemon
Summary: Although I couldn't repro the issue in T692, I did manage to point the "Diviner" repository at the "Phabricator" working copy and screw some stuff up on secure.phabricator.com. Before discovering commits in a repository, ensure the 'origin' remote points at the configured URI. This prevents issues where the working copy gets configured to point at an existing (but incorrect) checkout. Test Plan: - Ran gitcommitdiscovery daemon normally under "phd debug", saw it execute the "remote show -n" command and then start working. - Intentionally botched the config, got an exception: (Exception) Working copy '/INSECURE/repos/phabricator' has origin URL 'ssh://git@github.com/facebook/phabricator.git', but the configured URL 'git://github.com/facebook/diviner.git' is expected. Refusing to proceed. Reviewers: btrahan, jungejason Reviewed By: jungejason CC: aran, jungejason Maniphest Tasks: T692 Differential Revision: 1253
This commit is contained in:
parent
bd3c2355e8
commit
92f9741779
1 changed files with 17 additions and 1 deletions
|
@ -30,7 +30,23 @@ class PhabricatorRepositoryGitCommitDiscoveryDaemon
|
|||
throw new Exception("Repository is not a git repository.");
|
||||
}
|
||||
|
||||
$repository_phid = $repository->getPHID();
|
||||
list($remotes) = $repository->execxLocalCommand(
|
||||
'remote show -n origin');
|
||||
|
||||
$matches = null;
|
||||
if (!preg_match('/^\s*Fetch URL:\s*(.*?)\s*$/m', $remotes, $matches)) {
|
||||
throw new Exception(
|
||||
"Expected 'Fetch URL' in 'git remote show -n origin'.");
|
||||
}
|
||||
|
||||
$remote = $matches[1];
|
||||
$expect = $repository->getDetail('remote-uri');
|
||||
if ($remote != $expect) {
|
||||
$local_path = $repository->getLocalPath();
|
||||
throw new Exception(
|
||||
"Working copy '{$local_path}' has origin URL '{$remote}', but the ".
|
||||
"configured URL '{$expect}' is expected. Refusing to proceed.");
|
||||
}
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'branch -r --verbose --no-abbrev');
|
||||
|
|
Loading…
Reference in a new issue