public function testGitURIParsing() { $uri = new PhutilGitURI('git@host.com:path/to/something'); $this->assertEqual('git', $uri->getUser()); $this->assertEqual('host.com', $uri->getDomain()); $this->assertEqual('path/to/something', $uri->getPath()); $this->assertEqual('git@host.com:path/to/something', (string) $uri); $uri = new PhutilGitURI('host.com:path/to/something'); $this->assertEqual('', $uri->getUser()); $this->assertEqual('host.com', $uri->getDomain()); $this->assertEqual('path/to/something', $uri->getPath()); $this->assertEqual('host.com:path/to/something', (string) $uri); }
private function getRemoteURIUser($raw_uri) { $uri = new PhutilURI($raw_uri); if ($uri->getUser()) { return $uri->getUser(); } $git_uri = new PhutilGitURI($raw_uri); if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) { return $git_uri->getUser(); } return null; }
$uri = new PhutilURI($raw_uri); $proto = strtolower($uri->getProtocol()); if ($proto == 'http' || $proto == 'https' || $proto == 'svn') { $username = $repository->getDetail('http-login'); $secret = $repository->getDetail('http-pass'); $type = PassphrasePasswordCredentialType::CREDENTIAL_TYPE; } else { $username = $repository->getDetail('ssh-login'); if (!$username) { // If there's no explicit username, check for one in the URI. This is // possible with older repositories. $username = $uri->getUser(); if (!$username) { // Also check for a Git/SCP-style URI. $git_uri = new PhutilGitURI($raw_uri); $username = $git_uri->getUser(); } } $file = $repository->getDetail('ssh-keyfile'); if ($file) { $secret = $file; $type = PassphraseSSHPrivateKeyFileCredentialType::CREDENTIAL_TYPE; } else { $secret = $repository->getDetail('ssh-key'); $type = PassphraseSSHPrivateKeyTextCredentialType::CREDENTIAL_TYPE; } } if (!$username || !$secret) { echo pht('...no credentials set.') . "\n"; continue; }