Make sure we avoid cleanup running more than once per package on VcsDownloader
parent
0aaa815268
commit
55f122008b
|
@ -27,8 +27,8 @@ use Composer\Cache;
|
||||||
*/
|
*/
|
||||||
class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
{
|
{
|
||||||
private $hasStashedChanges = false;
|
private $hasStashedChanges = array();
|
||||||
private $hasDiscardedChanges = false;
|
private $hasDiscardedChanges = array();
|
||||||
private $gitUtil;
|
private $gitUtil;
|
||||||
private $cachedPackages = array();
|
private $cachedPackages = array();
|
||||||
|
|
||||||
|
@ -356,15 +356,15 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
protected function reapplyChanges($path)
|
protected function reapplyChanges($path)
|
||||||
{
|
{
|
||||||
$path = $this->normalizePath($path);
|
$path = $this->normalizePath($path);
|
||||||
if ($this->hasStashedChanges) {
|
if (!empty($this->hasStashedChanges[$path])) {
|
||||||
$this->hasStashedChanges = false;
|
unset($this->hasStashedChanges[$path]);
|
||||||
$this->io->writeError(' <info>Re-applying stashed changes</info>');
|
$this->io->writeError(' <info>Re-applying stashed changes</info>');
|
||||||
if (0 !== $this->process->execute('git stash pop', $output, $path)) {
|
if (0 !== $this->process->execute('git stash pop', $output, $path)) {
|
||||||
throw new \RuntimeException("Failed to apply stashed changes:\n\n".$this->process->getErrorOutput());
|
throw new \RuntimeException("Failed to apply stashed changes:\n\n".$this->process->getErrorOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hasDiscardedChanges = false;
|
unset($this->hasDiscardedChanges[$path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -379,7 +379,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
*/
|
*/
|
||||||
protected function updateToCommit($path, $reference, $branch, $date)
|
protected function updateToCommit($path, $reference, $branch, $date)
|
||||||
{
|
{
|
||||||
$force = $this->hasDiscardedChanges || $this->hasStashedChanges ? '-f ' : '';
|
$force = !empty($this->hasDiscardedChanges[$path]) || !empty($this->hasStashedChanges[$path]) ? '-f ' : '';
|
||||||
|
|
||||||
// This uses the "--" sequence to separate branch from file parameters.
|
// This uses the "--" sequence to separate branch from file parameters.
|
||||||
//
|
//
|
||||||
|
@ -484,7 +484,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput());
|
throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hasDiscardedChanges = true;
|
$this->hasDiscardedChanges[$path] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -498,7 +498,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
throw new \RuntimeException("Could not stash changes\n\n:".$this->process->getErrorOutput());
|
throw new \RuntimeException("Could not stash changes\n\n:".$this->process->getErrorOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hasStashedChanges = true;
|
$this->hasStashedChanges[$path] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,6 +35,8 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
||||||
protected $process;
|
protected $process;
|
||||||
/** @var Filesystem */
|
/** @var Filesystem */
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
|
/** @var array */
|
||||||
|
protected $hasCleanedChanges = array();
|
||||||
|
|
||||||
public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
|
public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
|
||||||
{
|
{
|
||||||
|
@ -90,6 +92,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
||||||
{
|
{
|
||||||
if ($type === 'update') {
|
if ($type === 'update') {
|
||||||
$this->cleanChanges($prevPackage, $path, true);
|
$this->cleanChanges($prevPackage, $path, true);
|
||||||
|
$this->hasCleanedChanges[$prevPackage->getUniqueName()] = true;
|
||||||
} elseif ($type === 'install') {
|
} elseif ($type === 'install') {
|
||||||
$this->filesystem->emptyDirectory($path);
|
$this->filesystem->emptyDirectory($path);
|
||||||
} elseif ($type === 'uninstall') {
|
} elseif ($type === 'uninstall') {
|
||||||
|
@ -102,9 +105,9 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
||||||
*/
|
*/
|
||||||
public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
|
public function cleanup($type, PackageInterface $package, $path, PackageInterface $prevPackage = null)
|
||||||
{
|
{
|
||||||
if ($type === 'update') {
|
if ($type === 'update' && isset($this->hasCleanedChanges[$prevPackage->getUniqueName()])) {
|
||||||
// TODO keep track of whether prepare was called for this package
|
|
||||||
$this->reapplyChanges($path);
|
$this->reapplyChanges($path);
|
||||||
|
unset($this->hasCleanedChanges[$prevPackage->getUniqueName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue