Skip to content

Commit 91c2326

Browse files
committed
Root project package can define patches and patch itself
1 parent 0a528b8 commit 91c2326

File tree

7 files changed

+83
-6
lines changed

7 files changed

+83
-6
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ the actions necessary to get there.
7272
Also you will not be able to specify patches in any composer package. You have to use a dedicated packages for this
7373
purpose. I can hardly imagine a legit use case when it would be desirable that installing package X will automatically
7474
patch some other package Y in your project without explicitly being advertised as a patchset.
75-
76-
### What is missing
77-
78-
- Patch the root package / files in root directory
79-
- Allow to specify patches in the root composer.json
8075

8176
## Running tests
8277

src/PatchCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Composer\Package\AliasPackage;
66
use Composer\Package\Package;
77
use Composer\Package\PackageInterface;
8+
use Composer\Package\RootPackageInterface;
89
use Composer\Repository\RepositoryInterface;
910

1011
use Psr\Log\LoggerInterface;
@@ -88,7 +89,7 @@ protected function collectFromPackage(PackageInterface $package)
8889
*/
8990
public function isAValidPatchset(PackageInterface $package)
9091
{
91-
return $package->getType() === 'patchset' && isset($package->getExtra()['patchset']);
92+
return ($package instanceof RootPackageInterface || $package->getType() === 'patchset') && isset($package->getExtra()['patchset']);
9293
}
9394

9495
/**

tests/Functional/CoreFeatureTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,50 @@ public function testRootPackageCanBePatched()
180180

181181
$this->assertThatComposerRunHasAppliedPatches($installRun, self::ROOT_PACKAGE_APPLICATIONS);
182182
}
183+
184+
public function testRootCanDefinePatches()
185+
{
186+
$project = $this->getSandbox()->createProjectSandBox('test/project-template-patchset', 'dev-master', [
187+
'require' => [
188+
'test/package-a'=> 'dev-master',
189+
'creativestyle/composer-plugin-patchset'=> 'dev-master'
190+
],
191+
'extra' => [
192+
'patchset' => [
193+
'test/package-a' => [
194+
[
195+
'description' => 'Patch in echo in the middle',
196+
'filename' => 'patches/package-a-patch-1.diff'
197+
]
198+
]
199+
]
200+
]
201+
]);
202+
203+
$installRun = $project->runComposerCommand('install');
204+
$this->assertThatComposerRunHasAppliedPatches($installRun, self::PACKAGEA_PATCH1_APPLICATIONS);
205+
}
206+
207+
public function testRootCanPatchItself()
208+
{
209+
$project = $this->getSandbox()->createProjectSandBox('test/project-template-patchset', 'dev-master', [
210+
'require' => [
211+
'test/package-a'=> 'dev-master',
212+
'creativestyle/composer-plugin-patchset'=> 'dev-master'
213+
],
214+
'extra' => [
215+
'patchset' => [
216+
'test/project-template-patchset' => [
217+
[
218+
'description' => 'Patch project root',
219+
'filename' => 'patches/root-project-patch-1.diff'
220+
]
221+
]
222+
]
223+
]
224+
]);
225+
226+
$installRun = $project->runComposerCommand('install');
227+
$this->assertThatComposerRunHasAppliedPatches($installRun, self::ROOT_PACKAGE_APPLICATIONS);
228+
}
183229
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "test/project-template-patchset",
3+
"type": "project",
4+
"version": "dev-master",
5+
"require": {},
6+
"minimum-stability": "dev"
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- a/src/test.php
2+
+++ b/src/test.php
3+
@@ -1,5 +1,6 @@
4+
<?php
5+
6+
echo 'first-echo';
7+
+echo 'patched-in-echo';
8+
echo 'last-echo';
9+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/src/root-code.php b/src/root-code.php
2+
index 78866cc..732f877 100644
3+
--- a/src/root-code.php
4+
+++ b/src/root-code.php
5+
@@ -2,6 +2,7 @@
6+
7+
foreach (['this', 'is', 'root', 'package', 'code'] as $word) {
8+
echo $word;
9+
+ echo "-is-patched\n";
10+
}
11+
12+
echo 'done';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
foreach (['this', 'is', 'root', 'package', 'code'] as $word) {
4+
echo $word;
5+
}
6+
7+
echo 'done';

0 commit comments

Comments
 (0)