Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Prerequisite actions are executed before the interactive part.

* `working-copy-check`: check that you don't have any VCS local changes
* Option `allow-ignore`: allow the user to skip the check when doing a release with `--ignore-check`
* Option `allowed-modifications`: allow the user to specify which files may be modified (does not support add, delete, rename, etc.)
* `display-last-changes`: display your last changes
* `tests-check`: run the project test suite
* Option `command`: command to run (default: *phpunit*)
Expand Down
31 changes: 26 additions & 5 deletions src/Liip/RMT/Prerequisite/WorkingCopyCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class WorkingCopyCheck extends BaseAction

public function __construct($options = array())
{
parent::__construct(array_merge(array('allow-ignore' => false), $options));
parent::__construct(array_merge(
array(
'allow-ignore' => false,
'allowed-modifications' => array(),
),
$options
));
}

public function getTitle()
Expand All @@ -54,20 +60,35 @@ public function execute()
);
}

$modCount = count(Context::get('vcs')->getLocalModifications());
$modCount = $this->getModCount();
if ($modCount > 0) {
throw new \Exception(
'Your working directory contains ' . $modCount . ' local modification' . ($modCount > 1 ? 's' : '') .
'. Use the --' . $this->ignoreCheckOptionName . ' option (along with the "allow-ignore" ' .
'configuration key set to true) to bypass this check.' . "\n" . 'WARNING, if your release task ' .
'include a commit action, the pending changes are going to be included in the release.',
'. Configure the "allowed-modifications" key or use the --' . $this->ignoreCheckOptionName . ' option ' .
'(along with the "allow-ignore" configuration key set to true) to bypass this check.' . "\n" .
'WARNING, if your release task include a commit action, the pending changes are going ' .
'to be included in the release.',
self::EXCEPTION_CODE
);
}

$this->confirmSuccess();
}

protected function getModCount(): int
{
$allowedModifications = $this->options['allowed-modifications'];
$localModifications = array_filter(
Context::get('vcs')->getLocalModifications(),
function($item) use ($allowedModifications) {
$filename = preg_replace('/^\s+M\s+/', '', $item);
return !in_array($filename, $allowedModifications);
}
);

return count($localModifications);
}

public function getInformationRequests()
{
return array(
Expand Down
17 changes: 17 additions & 0 deletions test/Liip/RMT/Tests/Functional/PrerequisitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ public function testWorkingCopyCheckFailsWithLocalModifications(): void
self::assertStringContainsString('local modification', implode("\n", $consoleOutput));
}

public function testWorkingCopyContinuesWithAllowedModifications(): void
{
$this->createConfig('simple', 'vcs-tag', array(
'prerequisites' => array('working-copy-check'=>array('allowed-modifications'=>array('CHANGELOG'))),
'vcs' => 'git',
));
$this->initGit();
exec('git tag 1');

// Release should continue even though file CHANGELOG has been modified.
exec('echo toto >> CHANGELOG');
exec('./RMT release -n 2>&1', $consoleOutput, $exitCode);
self::assertEquals(0, $exitCode, implode(PHP_EOL, $consoleOutput));
exec('git tag', $tags2);
self::assertEquals(array('1', '2'), $tags2);
}

public function testWorkingCopyWithIgnoreCheck(): void
{
$this->createConfig('simple', 'vcs-tag', array(
Expand Down
Loading