Refactor the whole cleanChanges/getLocalChanges code to be more strict with null returns Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>pull/10591/head
parent
076925ebef
commit
6c0a6e00b3
|
@ -109,7 +109,7 @@ EOT
|
||||||
$errors[$targetDir] = $targetDir . ' is a symbolic link.';
|
$errors[$targetDir] = $targetDir . ' is a symbolic link.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($changes = $downloader->getLocalChanges($package, $targetDir)) {
|
if (null !== ($changes = $downloader->getLocalChanges($package, $targetDir))) {
|
||||||
$errors[$targetDir] = $changes;
|
$errors[$targetDir] = $changes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,7 +500,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
||||||
$comparer->setSource($targetDir.'_compare');
|
$comparer->setSource($targetDir.'_compare');
|
||||||
$comparer->setUpdate($targetDir);
|
$comparer->setUpdate($targetDir);
|
||||||
$comparer->doCompare();
|
$comparer->doCompare();
|
||||||
$output = $comparer->getChanged(true, true);
|
$output = $comparer->getChangedAsString(true);
|
||||||
$this->filesystem->removeDirectory($targetDir.'_compare');
|
$this->filesystem->removeDirectory($targetDir.'_compare');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
@ -511,6 +511,8 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim($output);
|
$output = trim($output);
|
||||||
|
|
||||||
|
return strlen($output) > 0 ? $output : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,9 @@ class FossilDownloader extends VcsDownloader
|
||||||
|
|
||||||
$this->process->execute('fossil changes', $output, realpath($path));
|
$this->process->execute('fossil changes', $output, realpath($path));
|
||||||
|
|
||||||
return trim($output) ?: null;
|
$output = trim($output);
|
||||||
|
|
||||||
|
return strlen($output) > 0 ? $output : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -225,7 +225,9 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
|
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim($output) ?: null;
|
$output = trim($output);
|
||||||
|
|
||||||
|
return strlen($output) > 0 ? $output : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -338,7 +340,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||||
throw new \RuntimeException('Source directory ' . $path . ' has unpushed changes on the current branch: '."\n".$unpushed);
|
throw new \RuntimeException('Source directory ' . $path . ' has unpushed changes on the current branch: '."\n".$unpushed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$changes = $this->getLocalChanges($package, $path)) {
|
if (null === ($changes = $this->getLocalChanges($package, $path))) {
|
||||||
return \React\Promise\resolve();
|
return \React\Promise\resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,9 @@ class HgDownloader extends VcsDownloader
|
||||||
|
|
||||||
$this->process->execute('hg st', $output, realpath($path));
|
$this->process->execute('hg st', $output, realpath($path));
|
||||||
|
|
||||||
return trim($output) ?: null;
|
$output = trim($output);
|
||||||
|
|
||||||
|
return strlen($output) > 0 ? $output : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -132,7 +132,7 @@ class SvnDownloader extends VcsDownloader
|
||||||
*/
|
*/
|
||||||
protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface
|
protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface
|
||||||
{
|
{
|
||||||
if (!$changes = $this->getLocalChanges($package, $path)) {
|
if (null === ($changes = $this->getLocalChanges($package, $path))) {
|
||||||
return \React\Promise\resolve();
|
return \React\Promise\resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,11 @@ class Comparer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $toString
|
|
||||||
* @param bool $explicated
|
* @param bool $explicated
|
||||||
*
|
*
|
||||||
* @return array{changed?: string[], removed?: string[], added?: string[]}|string|false false if no change, string only if $toString is true
|
* @return array{changed?: string[], removed?: string[], added?: string[]}|false false if no change
|
||||||
*/
|
*/
|
||||||
public function getChanged(bool $toString = false, bool $explicated = false)
|
public function getChanged(bool $explicated = false)
|
||||||
{
|
{
|
||||||
$changed = $this->changed;
|
$changed = $this->changed;
|
||||||
if (!count($changed)) {
|
if (!count($changed)) {
|
||||||
|
@ -68,17 +67,29 @@ class Comparer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($toString) {
|
return $changed;
|
||||||
$strings = array();
|
}
|
||||||
foreach ($changed as $sectionKey => $itemSection) {
|
|
||||||
foreach ($itemSection as $itemKey => $item) {
|
/**
|
||||||
$strings[] = $item."\r\n";
|
* @param bool $explicated
|
||||||
}
|
*
|
||||||
}
|
* @return string empty string if no changes
|
||||||
$changed = implode("\r\n", $strings);
|
*/
|
||||||
|
public function getChangedAsString(bool $toString = false, bool $explicated = false): string
|
||||||
|
{
|
||||||
|
$changed = $this->getChanged($explicated);
|
||||||
|
if (false === $changed) {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $changed;
|
$strings = array();
|
||||||
|
foreach ($changed as $sectionKey => $itemSection) {
|
||||||
|
foreach ($itemSection as $itemKey => $item) {
|
||||||
|
$strings[] = $item."\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim(implode("\r\n", $strings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue