public function getRemoteUrl($remote, $operation = 'fetch')
{
$this->clearOutput();
$args = $operation === 'push' ? array('get-url', '--push', $remote) : array('get-url', $remote);
try {
return rtrim(call_user_func_array(array($this, 'remote'), $args)->getOutput());
} catch (GitException $e) {
// Fall back to parsing 'git remote -v' for older versions of git
// that do not support `git remote get-url`.
$identifier = " ({$operation})";
foreach (explode("\n", rtrim($this->remote('-v')->getOutput())) as $line) {
if (strpos($line, $remote) === 0 && strrpos($line, $identifier) === strlen($line) - strlen($identifier)) {
preg_match('/^.+\\t(.+) \\(' . $operation . '\\)$/', $line, $matches);
return $matches[1];
}
}
}
}