From a28d53d4c0423c175e56913ea3b6c8b3e66de1df Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 19 Oct 2012 11:43:49 +0200 Subject: [PATCH] Add missing v before checkout branches when needed, refs #1164 --- src/Composer/Downloader/GitDownloader.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index c7a829f5e..52e269024 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -164,10 +164,15 @@ class GitDownloader extends VcsDownloader $template = 'git checkout %s && git reset --hard %1$s'; $branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch); + $branches = null; + if (0 === $this->process->execute('git branch -r', $output, $path)) { + $branches = $output; + } + // check whether non-commitish are branches or tags, and fetch branches with the remote name $gitRef = $reference; if (!preg_match('{^[a-f0-9]{40}$}', $reference) - && 0 === $this->process->execute('git branch -r', $output, $path) + && $branches && preg_match('{^\s+composer/'.preg_quote($reference).'$}m', $output) ) { $command = sprintf('git checkout -B %s %s && git reset --hard %2$s', escapeshellarg($branch), escapeshellarg('composer/'.$reference)); @@ -178,6 +183,11 @@ class GitDownloader extends VcsDownloader // try to checkout branch by name and then reset it so it's on the proper branch name if (preg_match('{^[a-f0-9]{40}$}', $reference)) { + // add 'v' in front of the branch if it was stripped when generating the pretty name + if (!preg_match('{^\s+composer/'.preg_quote($branch).'$}m', $branches) && preg_match('{^\s+composer/v'.preg_quote($branch).'$}m', $branches)) { + $branch = 'v' . $branch; + } + $command = sprintf('git checkout %s', escapeshellarg($branch)); $fallbackCommand = sprintf('git checkout -B %s %s', escapeshellarg($branch), escapeshellarg('composer/'.$branch)); if (0 === $this->process->execute($command, $output, $path)