Skip to content

Commit 9a755f2

Browse files
committed
More usage docs
1 parent 77ff229 commit 9a755f2

File tree

4 files changed

+113
-19
lines changed

4 files changed

+113
-19
lines changed

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ It's (kind-of) an alternative to two other great plugins (differences will becom
1616
* [cweagans/composer-patches](https://github.com/cweagans/composer-patches)
1717

1818

19-
**If you're already convinced skip to [Usage Documentation](docs/usage.md).**
19+
**Continue reading this document for general description or skip to:**
20+
21+
* [Usage Documentation](docs/usage.md)
22+
* [Creating Patches Howto](docs/creating-patches.md)
23+
* [Testing](docs/testing.md)
2024

2125
## Feature comparison table
2226

@@ -86,13 +90,4 @@ plugins have done their work so patching source files in vendor will have no eff
8690
purpose. I can hardly imagine a legit use case when it would be desirable that installing package X will automatically
8791
patch some other package Y in your project without explicitly being advertised as a patchset.
8892

89-
## Running tests
90-
91-
Just start `vendor/bin/phpunit`.
92-
If you want to see the output of commands executed during functional testing use the `--debug` switch:
93-
```
94-
vendor/bin/phpunit --debug
95-
```
9693

97-
It's nice to also add the `--testdox` switch then.
98-

docs/creating-patches.md

Whitespace-only changes.

docs/testing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Testing the plugin
2+
3+
## Composer sandbox
4+
5+
This plugin uses a special sandbox which allows it to run composer as a separate process during testing.
6+
7+
A fake local packagist repository is created from [package definitions](tests/Functional/Fixtures/Packages)
8+
for the purpose of testing by using internally [Satis](https://github.com/composer/satis) as a library.
9+
10+
See the [ComposerSandbox](tests/Functional/Fixtures/ComposerSandbox.php) class for the details.
11+
12+
## Running tests
13+
14+
Just start `vendor/bin/phpunit`.
15+
If you want to see the output of commands executed during functional testing use the `--debug` switch:
16+
```
17+
vendor/bin/phpunit --debug
18+
```
19+
20+
It's nice to also add the `--testdox` switch then.
21+

docs/usage.md

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,99 @@
1-
## Usage
1+
# Basic Usage
22

3-
### Create *patchset* composer package
3+
There are two ways to specify and store patches, you can use any of them or both.
44

5-
### Define patches in your root package
5+
## Create *patchset* composer package
66

7-
### Applying patches to root package (root project folder)
7+
_Use this way to easily distribute your patchset and use it in multiple projects_
8+
9+
1. Create a new composer package and change the package type in `composer.json` to `patchset`
10+
so it looks like this:
11+
12+
```json
13+
{
14+
"name": "your-vendor/your-patchset-name",
15+
"type": "patchset",
16+
"version": "1.0",
17+
"require": {
18+
"creativestyle/composer-plugin-patchset": "^1.0"
19+
}
20+
}
21+
```
22+
23+
2. Place your diff patch files in any directories inside the package you want
24+
3. Define the patches in `composer.json` like this:
25+
26+
```json
27+
{
28+
"name": "your-vendor/your-patchset-name",
29+
"type": "patchset",
30+
"version": "1.0",
31+
"require": {
32+
"creativestyle/composer-plugin-patchset": "^1.0"
33+
},
34+
"extra": {
35+
"patchset": {
36+
"some-vendor-a/package-to-patch": [
37+
{
38+
"description": "Short patch description that is mandatory",
39+
"filename": "path/to/the-patch-file-relative-to-patchset-root.diff"
40+
},
41+
{
42+
"description": "Patches with no version specified will be always applied",
43+
"filename": "second-patch-for-the-same-package.diff"
44+
}
45+
],
46+
"some-vendor-b/package-to-patch": [
47+
{
48+
"description": "Patch some other package",
49+
"filename": "patches/your-other-package-patch.diff",
50+
}
51+
]
52+
}
53+
}
54+
}
55+
```
56+
57+
## Define patches in your root package
58+
59+
# Composer json configuration reference
60+
61+
## Patch properties
62+
63+
### `description` (string, mandatory)
64+
65+
Short description (or name) of your patch. Keep it short as it will be displayed during patching.
66+
67+
### `filename` (string, mandatory)
68+
69+
Path to your diff file relative to the root of your patchset. Patches can be stored anywhere within
70+
the package.
71+
72+
### `version-constraint` (string, default: `"*"`)
73+
74+
A composer semver version constraint. If specified then the patch application will be attempted
75+
only if the target package's version matches the constraint.
76+
77+
See [composer documenation](https://getcomposer.org/doc/articles/versions.md) for exact syntax reference.
78+
79+
### `strip-path-components` (integer, default: `1`)
80+
81+
How many leading path components to strip from filenames in diff when applying the patch.
82+
83+
This has the same effect as the `-p{x}` switch of the patch command, where `{x}` is the value of this parameter.
84+
85+
For 99% of the patches this will be the default `1`. Set this only if your patch was generated in some non-standard way.
86+
87+
# Notable use-cases
88+
89+
## Applying patches to root package (root project folder)
890

991
Define patches as you normally would. If your root package is not named the you should use special
1092
`__root__` as package name.
1193

12-
**CAUTION** Since root package cannot be reinstalled once patches are applied they cannot be removed!
94+
**CAUTION!** Since root package cannot be reinstalled once patches are applied they cannot be removed!
1395
This means that if you want to remove patches applied to root package you should reinstall the whole
1496
project manually. The plugin will warn you when this is the case but will not fail. It will try
1597
to apply any new root package patches though.
1698

1799
__New patches will be applied to the root package but then _application order_ is not guaranteed.__
18-
19-
### Options
20-
21-
#### Strip defined number of components when applying patch (`-pX`)

0 commit comments

Comments
 (0)