function Hg::runCommand
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Hg.php, line 49
Class
- Hg
- @author Jonas Renaudot <jonas.renaudot@gmail.com>
Namespace
Composer\UtilCode
public function runCommand(callable $commandCallable, string $url, ?string $cwd) : void {
$this->config
->prohibitUrlByConfig($url, $this->io);
// Try as is
$command = $commandCallable($url);
if (0 === $this->process
->execute($command, $ignoredOutput, $cwd)) {
return;
}
// Try with the authentication information available
if (Preg::isMatch('{^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?}mi', $url, $matches) && $this->io
->hasAuthentication($matches['host'])) {
if ($matches['proto'] === 'ssh') {
$user = '';
if ($matches['user'] !== null) {
$user = rawurlencode($matches['user']) . '@';
}
$authenticatedUrl = $matches['proto'] . '://' . $user . $matches['host'] . $matches['path'];
}
else {
$auth = $this->io
->getAuthentication($matches['host']);
$authenticatedUrl = $matches['proto'] . '://' . rawurlencode((string) $auth['username']) . ':' . rawurlencode((string) $auth['password']) . '@' . $matches['host'] . $matches['path'];
}
$command = $commandCallable($authenticatedUrl);
if (0 === $this->process
->execute($command, $ignoredOutput, $cwd)) {
return;
}
$error = $this->process
->getErrorOutput();
}
else {
$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);
}