File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 2
2
"name" : " jamescowie/composer-patcher" ,
3
3
"description" : " Apply patches using composer" ,
4
4
"license" : " MIT" ,
5
- "version" : " 1.0.1 " ,
5
+ "version" : " 1.0.2 " ,
6
6
"authors" : [
7
7
{
8
8
"name" : " jamescowie" ,
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public function __construct(SplFileInfo $fileInfo)
36
36
*/
37
37
final public function apply ()
38
38
{
39
- if ($ this ->canApply ()) {
39
+ if (! $ this -> isApplied () && $ this ->canApply ()) {
40
40
$ res = (bool )$ this ->doApply ();
41
41
42
42
if ($ res ) {
@@ -79,6 +79,28 @@ protected function canApply()
79
79
}
80
80
}
81
81
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
+
82
104
/**
83
105
* @return Output
84
106
*/
You can’t perform that action at this time.
0 commit comments