Skip to content

Commit

Permalink
Fix case where branches cannot be listed in GitDownloader, fixes #10888
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jun 22, 2022
1 parent 14476ec commit 5c68c2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Composer/Downloader/GitDownloader.php
Expand Up @@ -458,7 +458,7 @@ protected function updateToCommit(PackageInterface $package, $path, $reference,
// check whether non-commitish are branches or tags, and fetch branches with the remote name
$gitRef = $reference;
if (!Preg::isMatch('{^[a-f0-9]{40}$}', $reference)
&& $branches
&& null !== $branches
&& Preg::isMatch('{^\s+composer/'.preg_quote($reference).'$}m', $branches)
) {
$command = sprintf('git checkout '.$force.'-B %s %s -- && git reset --hard %2$s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$reference));
Expand All @@ -470,7 +470,7 @@ protected function updateToCommit(PackageInterface $package, $path, $reference,
// try to checkout branch by name and then reset it so it's on the proper branch name
if (Preg::isMatch('{^[a-f0-9]{40}$}', $reference)) {
// add 'v' in front of the branch if it was stripped when generating the pretty name
if (!Preg::isMatch('{^\s+composer/'.preg_quote($branch).'$}m', $branches) && Preg::isMatch('{^\s+composer/v'.preg_quote($branch).'$}m', $branches)) {
if (null !== $branches && !Preg::isMatch('{^\s+composer/'.preg_quote($branch).'$}m', $branches) && Preg::isMatch('{^\s+composer/v'.preg_quote($branch).'$}m', $branches)) {
$branch = 'v' . $branch;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Composer/Util/AuthHelper.php
Expand Up @@ -192,9 +192,9 @@ public function promptAuthIfNeeded($url, $origin, $statusCode, $reason = null, $
// fail if the console is not interactive
if (!$this->io->isInteractive()) {
if ($statusCode === 401) {
$message = "The '" . $url . "' URL required authentication.\nYou must be using the interactive console to authenticate";
$message = "The '" . $url . "' URL required authentication (HTTP 401).\nYou must be using the interactive console to authenticate";
} elseif ($statusCode === 403) {
$message = "The '" . $url . "' URL could not be accessed: " . $reason;
$message = "The '" . $url . "' URL could not be accessed (HTTP 403): " . $reason;
} else {
$message = "Unknown error code '" . $statusCode . "', reason: " . $reason;
}
Expand All @@ -210,7 +210,7 @@ public function promptAuthIfNeeded($url, $origin, $statusCode, $reason = null, $
return array('retry' => true, 'storeAuth' => false);
}

throw new TransportException("Invalid credentials for '" . $url . "', aborting.", $statusCode);
throw new TransportException("Invalid credentials (HTTP $statusCode) for '$url', aborting.", $statusCode);
}

$this->io->writeError(' Authentication required (<info>'.$origin.'</info>):');
Expand Down

0 comments on commit 5c68c2c

Please sign in to comment.