From 54054365e0841cd846b6e61ee235a993fca8e9db Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 20 Jun 2012 12:09:09 +0200 Subject: [PATCH] Add some comments --- src/Composer/Downloader/GitDownloader.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 22baff7fd..756218da5 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -75,14 +75,16 @@ class GitDownloader extends VcsDownloader $branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch); $date = $date->format('U'); + // guess which remote branch to look at first $command = 'git branch -r'; - if (1 === $this->process->execute($command, $output, $path)) { + if (0 !== $this->process->execute($command, $output, $path)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } $guessTemplate = 'git log --until=%s --date=raw -n1 --pretty=%%H %s'; foreach ($this->process->splitLines($output) as $line) { if (preg_match('{^composer/'.preg_quote($branch).'(?:\.x)?$}i', trim($line))) { + // find the previous commit by date in the given branch if (0 === $this->process->execute(sprintf($guessTemplate, $date, escapeshellarg(trim($line))), $output, $path)) { $newReference = trim($output); } @@ -92,12 +94,14 @@ class GitDownloader extends VcsDownloader } if (empty($newReference)) { + // no matching branch found, find the previous commit by date in all commits if (0 !== $this->process->execute(sprintf($guessTemplate, $date, '--all'), $output, $path)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } $newReference = trim($output); } + // checkout the new recovered ref $command = sprintf($template, escapeshellarg($newReference)); if (0 === $this->process->execute($command, $output, $path)) { $this->io->write(' '.$reference.' is gone (history was rewritten?), recovered by checking out '.$newReference);