From 04b099d9bab9c18718d1086f076184ef16825b4e Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 27 Nov 2013 11:09:07 -0800 Subject: [PATCH] Fix an issue with repository credential migration for older repositories Summary: See IRC. It's possible to have a functional repository with the SSH username only in the URL. Look there if the username property isn't set. These should all be older repostiories. Test Plan: Did a `--force --apply` upgrade. Reviewers: btrahan, chad Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D7665 --- .../patches/20131121.repocredentials.2.mig.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/resources/sql/patches/20131121.repocredentials.2.mig.php b/resources/sql/patches/20131121.repocredentials.2.mig.php index d9735d6b5b..e147cc8b51 100644 --- a/resources/sql/patches/20131121.repocredentials.2.mig.php +++ b/resources/sql/patches/20131121.repocredentials.2.mig.php @@ -14,13 +14,13 @@ foreach (new LiskMigrationIterator($table) as $repository) { continue; } - $uri = $repository->getRemoteURI(); - if (!$uri) { + $raw_uri = $repository->getRemoteURI(); + if (!$raw_uri) { echo "...no remote URI.\n"; continue; } - $uri = new PhutilURI($uri); + $uri = new PhutilURI($raw_uri); $proto = strtolower($uri->getProtocol()); if ($proto == 'http' || $proto == 'https' || $proto == 'svn') { @@ -29,6 +29,16 @@ foreach (new LiskMigrationIterator($table) as $repository) { $type = PassphraseCredentialTypePassword::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;