Fix fetching from Mercurial repos: ssh, branches
This commit is contained in:
parent
4d0911f2a9
commit
b1edf3dc27
|
@ -42,7 +42,7 @@ class MercurialBuild extends Build
|
|||
}
|
||||
|
||||
if (!$success) {
|
||||
$builder->logFailure('Failed to clone remote git repository.');
|
||||
$builder->logFailure('Failed to clone remote hg repository.');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -57,16 +57,34 @@ class MercurialBuild extends Build
|
|||
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.
|
||||
*/
|
||||
protected function cloneBySsh(Builder $builder, $cloneTo)
|
||||
{
|
||||
$keyFile = $this->writeSshKey();
|
||||
$keyFile = $this->writeSshKey($cloneTo);
|
||||
|
||||
// Do the git clone:
|
||||
$cmd = 'hg clone --ssh "ssh -i '.$keyFile.'" %s "%s"';
|
||||
$success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo);
|
||||
// Do the hg clone:
|
||||
$cmd = 'hg clone --ssh "ssh -i '.$keyFile.'" %s "%s" -r %s';
|
||||
$success = $builder->executeCommand($cmd, $this->getCloneUrl(), $cloneTo, $this->getBranch());
|
||||
|
||||
if ($success) {
|
||||
$success = $this->postCloneSetup($builder, $cloneTo);
|
||||
|
|
Loading…
Reference in a new issue