Fix fetching from Mercurial repos: ssh, branches

This commit is contained in:
bochkovprivate 2016-06-29 08:34:42 +02:00
parent 4d0911f2a9
commit b1edf3dc27

View file

@ -42,7 +42,7 @@ class MercurialBuild extends Build
} }
if (!$success) { if (!$success) {
$builder->logFailure('Failed to clone remote git repository.'); $builder->logFailure('Failed to clone remote hg repository.');
return false; return false;
} }
@ -57,16 +57,34 @@ class MercurialBuild extends Build
return $builder->executeCommand('hg clone %s "%s" -r %s', $this->getCloneUrl(), $cloneTo, $this->getBranch()); return $builder->executeCommand('hg clone %s "%s" -r %s', $this->getCloneUrl(), $cloneTo, $this->getBranch());
} }
/**
* Create an SSH key file on disk for this build.
* @param $cloneTo
* @return string
*/
protected function writeSshKey($cloneTo)
{
$keyPath = dirname($cloneTo . '/temp');
$keyFile = $keyPath . '.key';
// Write the contents of this project's hg key to the file:
file_put_contents($keyFile, $this->getProject()->getSshPrivateKey());
chmod($keyFile, 0600);
// Return the filename:
return $keyFile;
}
/** /**
* Use an SSH-based Mercurial clone. * Use an SSH-based Mercurial clone.
*/ */
protected function cloneBySsh(Builder $builder, $cloneTo) protected function cloneBySsh(Builder $builder, $cloneTo)
{ {
$keyFile = $this->writeSshKey(); $keyFile = $this->writeSshKey($cloneTo);
// Do the git clone: // Do the hg clone:
$cmd = 'hg clone --ssh "ssh -i '.$keyFile.'" %s "%s"'; $cmd = 'hg clone --ssh "ssh -i '.$keyFile.'" %s "%s" -r %s';
$success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo); $success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo, $this->getBranch());
if ($success) { if ($success) {
$success = $this->postCloneSetup($builder, $cloneTo); $success = $this->postCloneSetup($builder, $cloneTo);