Skip to content

Commit 36d9f28

Browse files
authored
Merge pull request #5 from pmclain/hotfix/patch-errors
Dry run revert to test if patch is applied
2 parents 39711ae + 15f8153 commit 36d9f28

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jamescowie/composer-patcher",
33
"description": "Apply patches using composer",
44
"license": "MIT",
5-
"version": "1.0.1",
5+
"version": "1.0.2",
66
"authors": [
77
{
88
"name": "jamescowie",

src/Inviqa/Patch/Patch.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(SplFileInfo $fileInfo)
3636
*/
3737
final public function apply()
3838
{
39-
if ($this->canApply()) {
39+
if (!$this->isApplied() && $this->canApply()) {
4040
$res = (bool)$this->doApply();
4141

4242
if ($res) {
@@ -79,6 +79,28 @@ protected function canApply()
7979
}
8080
}
8181

82+
/**
83+
* @return bool
84+
*/
85+
protected function isApplied()
86+
{
87+
$patchPath = ProcessUtils::escapeArgument($this->fileInfo->getRealPath());
88+
$process = new Process("patch --dry-run -p 1 -R < $patchPath");
89+
try {
90+
$process->mustRun();
91+
$result = $process->getExitCode() === 0;
92+
93+
if ($result) {
94+
$this->getOutput()->writeln("<info>Patch {$this->fileInfo->getFilename()} already applied.</info>");
95+
}
96+
97+
return $result;
98+
} catch (\Exception $e) {
99+
$this->getOutput()->writeln("<comment>{$e->getMessage()}</comment>");
100+
return false;
101+
}
102+
}
103+
82104
/**
83105
* @return Output
84106
*/

0 commit comments

Comments
 (0)