Allow for SSH URLs when using hg repository type (#11878)
parent
75ccf6557a
commit
a6947f116a
|
@ -58,10 +58,20 @@ class Hg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try with the authentication information available
|
// Try with the authentication information available
|
||||||
if (Preg::isMatch('{^(https?)://((.+)(?:\:(.+))?@)?([^/]+)(/.*)?}mi', $url, $match) && $this->io->hasAuthentication((string) $match[5])) {
|
if (
|
||||||
$auth = $this->io->getAuthentication((string) $match[5]);
|
Preg::isMatch('{^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?}mi', $url, $matches)
|
||||||
$authenticatedUrl = $match[1] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[5] . $match[6];
|
&& $this->io->hasAuthentication((string) $matches['host'])
|
||||||
|
) {
|
||||||
|
if ($matches['proto'] === 'ssh') {
|
||||||
|
$user = '';
|
||||||
|
if ($matches['user'] !== '' && $matches['user'] !== null) {
|
||||||
|
$user = rawurlencode($matches['user']) . '@';
|
||||||
|
}
|
||||||
|
$authenticatedUrl = $matches['proto'] . '://' . $user . $matches['host'] . $matches['path'];
|
||||||
|
} else {
|
||||||
|
$auth = $this->io->getAuthentication((string) $matches['host']);
|
||||||
|
$authenticatedUrl = $matches['proto'] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $matches['host'] . $matches['path'];
|
||||||
|
}
|
||||||
$command = $commandCallable($authenticatedUrl);
|
$command = $commandCallable($authenticatedUrl);
|
||||||
|
|
||||||
if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
|
if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
|
||||||
|
@ -70,10 +80,10 @@ class Hg
|
||||||
|
|
||||||
$error = $this->process->getErrorOutput();
|
$error = $this->process->getErrorOutput();
|
||||||
} else {
|
} else {
|
||||||
$error = 'The given URL (' . $url . ') does not match the required format (http(s)://(username:password@)example.com/path-to-repository)';
|
$error = 'The given URL (' .$url. ') does not match the required format (ssh|http(s)://(username:password@)example.com/path-to-repository)';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->throwException('Failed to clone ' . $url . ', ' . "\n\n" . $error, $url);
|
$this->throwException("Failed to clone $url, \n\n" . $error, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,7 +94,9 @@ class Hg
|
||||||
private function throwException($message, string $url): void
|
private function throwException($message, string $url): void
|
||||||
{
|
{
|
||||||
if (null === self::getVersion($this->process)) {
|
if (null === self::getVersion($this->process)) {
|
||||||
throw new \RuntimeException(Url::sanitize('Failed to clone ' . $url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()));
|
throw new \RuntimeException(Url::sanitize(
|
||||||
|
'Failed to clone ' . $url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException(Url::sanitize($message));
|
throw new \RuntimeException(Url::sanitize($message));
|
||||||
|
|
Loading…
Reference in New Issue