GitWrapper\GitWorkingCopy::getRemoteUrl PHP Method

getRemoteUrl() public method

Returns the fetch or push URL of a given remote.
public getRemoteUrl ( string $remote, string $operation = 'fetch' ) : string
$remote string The name of the remote for which to return the fetch or push URL.
$operation string The operation for which to return the remote. Can be either 'fetch' or 'push'. Defaults to 'fetch'.
return string The URL.
    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];
                }
            }
        }
    }