diff --git a/scripts/ssh/ssh-connect.php b/scripts/ssh/ssh-connect.php index 03e1caa77a..f02bafb936 100755 --- a/scripts/ssh/ssh-connect.php +++ b/scripts/ssh/ssh-connect.php @@ -7,21 +7,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -$target_name = getenv('PHABRICATOR_SSH_TARGET'); -if (!$target_name) { - throw new Exception(pht("No 'PHABRICATOR_SSH_TARGET' in environment!")); -} - -$viewer = PhabricatorUser::getOmnipotentUser(); - -$repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) - ->withCallsigns(array($target_name)) - ->executeOne(); -if (!$repository) { - throw new Exception(pht('No repository with callsign "%s"!', $target_name)); -} - $pattern = array(); $arguments = array(); @@ -30,8 +15,9 @@ $pattern[] = 'ssh'; $pattern[] = '-o'; $pattern[] = 'StrictHostKeyChecking=no'; -$credential_phid = $repository->getCredentialPHID(); +$credential_phid = getenv('PHABRICATOR_CREDENTIAL'); if ($credential_phid) { + $viewer = PhabricatorUser::getOmnipotentUser(); $key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer); $pattern[] = '-l %P'; diff --git a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php index 88c708ac20..8d84a8be5f 100644 --- a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php +++ b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php @@ -252,6 +252,15 @@ final class PhabricatorRepositoryPullLocalDaemon $this->checkIfRepositoryIsFullyImported($repository); + try { + $this->pushToMirrors($repository); + } catch (Exception $ex) { + // TODO: We should report these into the UI properly, but for + // now just complain. These errors are much less severe than + // pull errors. + phlog($ex); + } + if ($refs !== null) { return (bool)count($refs); } else { @@ -802,4 +811,43 @@ final class PhabricatorRepositoryPullLocalDaemon } + private function pushToMirrors(PhabricatorRepository $repository) { + if (!$repository->canMirror()) { + return; + } + + $mirrors = id(new PhabricatorRepositoryMirrorQuery()) + ->setViewer($this->getViewer()) + ->withRepositoryPHIDs(array($repository->getPHID())) + ->execute(); + + // TODO: This is a little bit janky, but we don't have first-class + // infrastructure for running remote commands against an arbitrary remote + // right now. Just make an emphemeral copy of the repository and muck with + // it a little bit. In the medium term, we should pull this command stuff + // out and use it here and for "Land to ...". + + $proxy = clone $repository; + $proxy->makeEphemeral(); + + $proxy->setDetail('hosting-enabled', false); + foreach ($mirrors as $mirror) { + $proxy->setDetail('remote-uri', $mirror->getRemoteURI()); + $proxy->setCredentialPHID($mirror->getCredentialPHID()); + + $this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI())); + + if (!$proxy->isGit()) { + throw new Exception('Unsupported VCS!'); + } + + $future = $proxy->getRemoteCommandFuture( + 'push --verbose --mirror -- %s', + $proxy->getRemoteURI()); + + $future + ->setCWD($proxy->getLocalPath()) + ->resolvex(); + } + } } diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 3bbaa9901b..40665be51a 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -337,7 +337,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO if ($this->shouldUseSSH()) { // NOTE: This is read by `bin/ssh-connect`, and tells it which credentials // to use. - $env['PHABRICATOR_SSH_TARGET'] = $this->getCallsign(); + $env['PHABRICATOR_CREDENTIAL'] = $this->getCredentialPHID(); switch ($this->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: // Force SVN to use `bin/ssh-connect`.