1
0
Fork 0

stash untracked and force checkout if discarding changes

pull/4618/head
Steve Buzonas 2015-02-26 09:47:50 -05:00 committed by Jordi Boggiano
parent 30e6a63958
commit 27d51642c8
1 changed files with 7 additions and 4 deletions

View File

@ -218,12 +218,15 @@ class GitDownloader extends VcsDownloader
*/ */
protected function updateToCommit($path, $reference, $branch, $date) protected function updateToCommit($path, $reference, $branch, $date)
{ {
$discardChanges = $this->config->get('discard-changes');
$force = true === $discardChanges || 'stash' === $discardChanges ? '-f ' : '';
// This uses the "--" sequence to separate branch from file parameters. // This uses the "--" sequence to separate branch from file parameters.
// //
// Otherwise git tries the branch name as well as file name. // Otherwise git tries the branch name as well as file name.
// If the non-existent branch is actually the name of a file, the file // If the non-existent branch is actually the name of a file, the file
// is checked out. // is checked out.
$template = 'git checkout %s -- && git reset --hard %1$s --'; $template = 'git checkout '.$force.'%s -- && git reset --hard %1$s --';
$branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch); $branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch);
$branches = null; $branches = null;
@ -237,7 +240,7 @@ class GitDownloader extends VcsDownloader
&& $branches && $branches
&& preg_match('{^\s+composer/'.preg_quote($reference).'$}m', $branches) && preg_match('{^\s+composer/'.preg_quote($reference).'$}m', $branches)
) { ) {
$command = sprintf('git checkout -B %s %s -- && git reset --hard %2$s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$reference)); $command = sprintf('git checkout '.$force.'-B %s %s -- && git reset --hard %2$s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$reference));
if (0 === $this->process->execute($command, $output, $path)) { if (0 === $this->process->execute($command, $output, $path)) {
return; return;
} }
@ -251,7 +254,7 @@ class GitDownloader extends VcsDownloader
} }
$command = sprintf('git checkout %s --', ProcessExecutor::escape($branch)); $command = sprintf('git checkout %s --', ProcessExecutor::escape($branch));
$fallbackCommand = sprintf('git checkout -B %s %s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$branch)); $fallbackCommand = sprintf('git checkout '.$force.'-B %s %s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$branch));
if (0 === $this->process->execute($command, $output, $path) if (0 === $this->process->execute($command, $output, $path)
|| 0 === $this->process->execute($fallbackCommand, $output, $path) || 0 === $this->process->execute($fallbackCommand, $output, $path)
) { ) {
@ -323,7 +326,7 @@ class GitDownloader extends VcsDownloader
protected function stashChanges($path) protected function stashChanges($path)
{ {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (0 !== $this->process->execute('git stash', $output, $path)) { if (0 !== $this->process->execute('git stash --include-untracked', $output, $path)) {
throw new \RuntimeException("Could not stash changes\n\n:".$this->process->getErrorOutput()); throw new \RuntimeException("Could not stash changes\n\n:".$this->process->getErrorOutput());
} }