function GitDownloader::cleanChanges
@inheritDoc
Overrides VcsDownloader::cleanChanges
File
-
vendor/
composer/ composer/ src/ Composer/ Downloader/ GitDownloader.php, line 328
Class
- GitDownloader
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\DownloaderCode
protected function cleanChanges(PackageInterface $package, string $path, bool $update) : PromiseInterface {
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
$unpushed = $this->getUnpushedChanges($package, $path);
if ($unpushed && ($this->io
->isInteractive() || $this->config
->get('discard-changes') !== true)) {
throw new \RuntimeException('Source directory ' . $path . ' has unpushed changes on the current branch: ' . "\n" . $unpushed);
}
if (null === ($changes = $this->getLocalChanges($package, $path))) {
return \React\Promise\resolve(null);
}
if (!$this->io
->isInteractive()) {
$discardChanges = $this->config
->get('discard-changes');
if (true === $discardChanges) {
return $this->discardChanges($path);
}
if ('stash' === $discardChanges) {
if (!$update) {
return parent::cleanChanges($package, $path, $update);
}
return $this->stashChanges($path);
}
return parent::cleanChanges($package, $path, $update);
}
$changes = array_map(static function ($elem) : string {
return ' ' . $elem;
}, Preg::split('{\\s*\\r?\\n\\s*}', $changes));
$this->io
->writeError(' <error>' . $package->getPrettyName() . ' has modified files:</error>');
$this->io
->writeError(array_slice($changes, 0, 10));
if (count($changes) > 10) {
$this->io
->writeError(' <info>' . (count($changes) - 10) . ' more files modified, choose "v" to view the full list</info>');
}
while (true) {
switch ($this->io
->ask(' <info>Discard changes [y,n,v,d,' . ($update ? 's,' : '') . '?]?</info> ', '?')) {
case 'y':
$this->discardChanges($path);
break 2;
case 's':
if (!$update) {
goto help;
}
$this->stashChanges($path);
break 2;
case 'n':
throw new \RuntimeException('Update aborted');
case 'v':
$this->io
->writeError($changes);
break;
case 'd':
$this->viewDiff($path);
break;
case '?':
default:
help:
$this->io
->writeError([
' y - discard changes and apply the ' . ($update ? 'update' : 'uninstall'),
' n - abort the ' . ($update ? 'update' : 'uninstall') . ' and let you manually clean things up',
' v - view modified files',
' d - view local modifications (diff)',
]);
if ($update) {
$this->io
->writeError(' s - stash changes and try to reapply them after the update');
}
$this->io
->writeError(' ? - print help');
break;
}
}
return \React\Promise\resolve(null);
}