patchy-cli 0.0.4 → 0.0.5-pr.158.3cfadb1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -41
- package/assets/logo.png +0 -0
- package/package.json +9 -7
- package/schema.json +31 -0
package/README.md
CHANGED
|
@@ -1,42 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img alt="Patchy logo" src="./assets/logo.png" height="128">
|
|
3
|
+
<h1>Patchy</h1>
|
|
4
|
+
<p>A CLI for generating and applying patches to git repositories.</p>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<a href="https://www.npmjs.com/package/patchy-cli"><img alt="NPM version" src="https://img.shields.io/npm/v/patchy-cli.svg?style=for-the-badge&labelColor=000000"></a>
|
|
7
|
+
<a href="https://github.com/richardgill/patchy/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/patchy-cli.svg?style=for-the-badge&labelColor=000000"></a>
|
|
8
|
+
<a href="https://github.com/richardgill/patchy/issues"><img alt="GitHub issues" src="https://img.shields.io/github/issues/richardgill/patchy.svg?style=for-the-badge&labelColor=000000"></a>
|
|
9
|
+
</div>
|
|
4
10
|
|
|
5
|
-
##
|
|
11
|
+
## Patches vs forks
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
A traditional fork means maintaining a separate repository or long-lived branch. Over time, your history diverges from upstream, which can make updates painful.
|
|
8
14
|
|
|
9
|
-
`
|
|
15
|
+
With patches, you store changes as `.diff` files alongside the upstream repo. You can inspect them, edit them, and apply them to a fresh clone of the repo.
|
|
16
|
+
|
|
17
|
+
## What is Patchy?
|
|
18
|
+
|
|
19
|
+
Patchy helps you **generate** and **apply** `.diff` patches for a git repo you've cloned on your machine.
|
|
20
|
+
|
|
21
|
+
It's opinionated and has [conventions](#patch-file-layout) about how the `.diff` files are stored.
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
Starting a patch-based fork of https://github.com/octocat/spoon-knife.
|
|
26
|
+
|
|
27
|
+
### Setup Patchy
|
|
28
|
+
|
|
29
|
+
Create a folder for the fork: `mkdir spoon-knife-fork && cd spoon-knife-fork`
|
|
30
|
+
|
|
31
|
+
- [Install Patchy](#install)
|
|
32
|
+
- Run `patchy init`
|
|
33
|
+
- press enter to select all the default options
|
|
34
|
+
|
|
35
|
+
`patchy init` creates your config: `./patchy.json` ([full reference](#patchyjson))
|
|
10
36
|
```json5
|
|
11
37
|
{
|
|
12
38
|
"repo_url": "https://github.com/octocat/spoon-knife",
|
|
13
39
|
"patches_dir": "./patches/",
|
|
14
40
|
"clones_dir": "./clones/",
|
|
15
41
|
"repo_dir": "spoon-knife",
|
|
42
|
+
"ref": "main"
|
|
16
43
|
}
|
|
17
44
|
```
|
|
18
45
|
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
patchy init
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
You can `patchy repo clone` the repo into `./clones/` to complete the setup.
|
|
25
|
-
|
|
26
|
-
Now you'll have
|
|
46
|
+
`patchy init` also creates an empty `./patches` folder and clones the spoon-knife repo into `./clones`:
|
|
27
47
|
|
|
28
48
|
```
|
|
29
49
|
./
|
|
30
50
|
├── patches/
|
|
31
51
|
├── clones/
|
|
32
52
|
│ └── spoon-knife/
|
|
33
|
-
│
|
|
53
|
+
│ └── path/to/existingFile.txt
|
|
34
54
|
└── patchy.json
|
|
35
55
|
```
|
|
36
56
|
|
|
37
|
-
|
|
57
|
+
### Make changes to the cloned repo
|
|
58
|
+
|
|
59
|
+
We can now make changes directly in the cloned spoon-knife repo:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
echo "edit existing file" >> clones/spoon-knife/path/to/existingFile.txt
|
|
63
|
+
echo "new file" > clones/spoon-knife/path/to/newFile.txt
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Generate patches:
|
|
67
|
+
|
|
68
|
+
To generate the patches for the changes run `patchy generate`:
|
|
38
69
|
|
|
39
|
-
And generate patches with `patchy generate`
|
|
40
70
|
|
|
41
71
|
```
|
|
42
72
|
./
|
|
@@ -49,36 +79,37 @@ And generate patches with `patchy generate`
|
|
|
49
79
|
│ └── path/to/newFile.txt
|
|
50
80
|
└── patchy.json
|
|
51
81
|
```
|
|
52
|
-
|
|
53
82
|
- **Edits** are stored as `.diff` files e.g. `existingFile.txt.diff`.
|
|
54
|
-
- **New files** are copied as regular files e.g. `newFile.txt
|
|
55
|
-
|
|
56
|
-
You can reapply your changes later with:
|
|
83
|
+
- **New files** are copied as regular files e.g. `newFile.txt` (easier to inspect and edit directly).
|
|
57
84
|
|
|
58
|
-
|
|
85
|
+
### Reapplying patches:
|
|
59
86
|
|
|
60
|
-
|
|
87
|
+
Reset the current upstream repo `patchy repo reset main`, which will reset everything to `main`:
|
|
61
88
|
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
89
|
+
```
|
|
90
|
+
./
|
|
91
|
+
├── clones/
|
|
92
|
+
│ └── spoon-knife/ <<< reset
|
|
93
|
+
│ ├── path/to/existingFile.txt
|
|
94
|
+
├── patches/
|
|
95
|
+
│ ├── path/to/existingFile.txt.diff
|
|
96
|
+
│ └── path/to/newFile.txt
|
|
97
|
+
└── patchy.json
|
|
98
|
+
```
|
|
72
99
|
|
|
73
|
-
|
|
74
|
-
"clones_dir": "./clones/", // Override: --clones-dir | env: PATCHY_CLONES_DIR
|
|
100
|
+
Apply the patches back to the cloned repo with: `patchy apply`
|
|
75
101
|
|
|
76
|
-
// Git ref to checkout (branch, tag, SHA).
|
|
77
|
-
"ref": "main" // Override: --ref | env: PATCHY_REF
|
|
78
|
-
}
|
|
79
102
|
```
|
|
80
|
-
|
|
81
|
-
|
|
103
|
+
./
|
|
104
|
+
├── clones/
|
|
105
|
+
│ └── spoon-knife/
|
|
106
|
+
│ ├── path/to/existingFile.txt (modified)
|
|
107
|
+
│ └── path/to/newFile.txt (added)
|
|
108
|
+
├── patches/
|
|
109
|
+
│ ├── path/to/existingFile.txt.diff
|
|
110
|
+
│ └── path/to/newFile.txt
|
|
111
|
+
└── patchy.json
|
|
112
|
+
```
|
|
82
113
|
|
|
83
114
|
## Getting started
|
|
84
115
|
|
|
@@ -104,14 +135,60 @@ Or use directly without installing:
|
|
|
104
135
|
npx patchy-cli@latest
|
|
105
136
|
```
|
|
106
137
|
|
|
107
|
-
### Initialize
|
|
138
|
+
### Initialize Patchy
|
|
108
139
|
|
|
109
|
-
Run this command to initialize
|
|
140
|
+
Run this command to initialize Patchy in your project folder:
|
|
110
141
|
|
|
111
142
|
```sh
|
|
112
143
|
patchy init
|
|
113
144
|
```
|
|
114
145
|
|
|
146
|
+
## `patchy.json` reference
|
|
147
|
+
|
|
148
|
+
```jsonc
|
|
149
|
+
{
|
|
150
|
+
// Git URL to clone from.
|
|
151
|
+
"repo_url": "https://github.com/example/repo.git", // Override: --repo-url | env: PATCHY_REPO_URL
|
|
152
|
+
|
|
153
|
+
// Path to repo you're generating patches from or applying patches to.
|
|
154
|
+
"repo_dir": "~/repos/repo", // Override: --repo-dir | env: PATCHY_REPO_DIR
|
|
155
|
+
|
|
156
|
+
// Directory containing patch files.
|
|
157
|
+
"patches_dir": "./patches/", // Override: --patches-dir | env: PATCHY_PATCHES_DIR
|
|
158
|
+
|
|
159
|
+
// Parent directory for cloning repos. You can easily clone more repos here from repo_url.
|
|
160
|
+
"clones_dir": "./clones/", // Override: --clones-dir | env: PATCHY_CLONES_DIR
|
|
161
|
+
|
|
162
|
+
// Git ref to checkout (branch, tag, SHA).
|
|
163
|
+
"ref": "main" // Override: --ref | env: PATCHY_REF
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
Precedence: CLI flags > Environment variables > `patchy.json`
|
|
167
|
+
|
|
168
|
+
`patchy.json` use jsonc, so comments are allowed.
|
|
169
|
+
|
|
170
|
+
## Patch file layout
|
|
171
|
+
|
|
172
|
+
The `patches/` directory (customizable via [`patches_dir`](#patchyjson)) uses the same folder structure as `repo_dir`:
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
./
|
|
176
|
+
├── patches/
|
|
177
|
+
│ ├── path/to/existingFile.txt.diff
|
|
178
|
+
│ └── path/to/newFile.txt
|
|
179
|
+
├── clones/
|
|
180
|
+
│ └── repo-clone-1/
|
|
181
|
+
│ ├── path/to/existingFile.txt (modified)
|
|
182
|
+
│ └── path/to/newFile.txt (added)
|
|
183
|
+
└── patchy.json
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Two types of patch files:**
|
|
187
|
+
- **`.diff` files** — For modified existing files (generated via `git diff HEAD`)
|
|
188
|
+
- **Plain files** — For newly added files (copied verbatim for easier inspection and editing)
|
|
189
|
+
|
|
190
|
+
`patchy generate` automatically removes stale files in `patches/` that no longer correspond to changes in `repo_dir`.
|
|
191
|
+
|
|
115
192
|
## Commands
|
|
116
193
|
|
|
117
194
|
### `patchy generate`
|
|
@@ -122,6 +199,8 @@ Generate `.diff` files and new files into `./patches/` based on current `git dif
|
|
|
122
199
|
patchy generate [--repo-dir] [--patches-dir] [--dry-run]
|
|
123
200
|
```
|
|
124
201
|
|
|
202
|
+
Note: `patchy generate` is destructive and will remove any unneeded files in your `./patches/` folder.
|
|
203
|
+
|
|
125
204
|
### `patchy apply`
|
|
126
205
|
|
|
127
206
|
Apply patch files from `patches/` into `repo_dir`.
|
package/assets/logo.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "patchy-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-pr.158.3cfadb1",
|
|
4
4
|
"description": "A CLI tool for managing Git patch workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"patchy": "./bin/patchy.cjs"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"bin"
|
|
10
|
+
"bin",
|
|
11
|
+
"schema.json",
|
|
12
|
+
"assets"
|
|
11
13
|
],
|
|
12
14
|
"scripts": {
|
|
13
15
|
"build": "bun run ./scripts/build.ts",
|
|
@@ -60,11 +62,11 @@
|
|
|
60
62
|
"url": "https://github.com/richardgill/patchy"
|
|
61
63
|
},
|
|
62
64
|
"optionalDependencies": {
|
|
63
|
-
"patchy-cli-linux-x64": "0.0.
|
|
64
|
-
"patchy-cli-linux-arm64": "0.0.
|
|
65
|
-
"patchy-cli-darwin-x64": "0.0.
|
|
66
|
-
"patchy-cli-darwin-arm64": "0.0.
|
|
67
|
-
"patchy-cli-windows-x64": "0.0.
|
|
65
|
+
"patchy-cli-linux-x64": "0.0.5-pr.158.3cfadb1",
|
|
66
|
+
"patchy-cli-linux-arm64": "0.0.5-pr.158.3cfadb1",
|
|
67
|
+
"patchy-cli-darwin-x64": "0.0.5-pr.158.3cfadb1",
|
|
68
|
+
"patchy-cli-darwin-arm64": "0.0.5-pr.158.3cfadb1",
|
|
69
|
+
"patchy-cli-windows-x64": "0.0.5-pr.158.3cfadb1"
|
|
68
70
|
},
|
|
69
71
|
"publishConfig": {
|
|
70
72
|
"access": "public"
|
package/schema.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Patchy Configuration",
|
|
3
|
+
"description": "Configuration file for patchy-cli, a tool for managing Git patch workflows",
|
|
4
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"repo_url": {
|
|
8
|
+
"type": "string"
|
|
9
|
+
},
|
|
10
|
+
"repo_dir": {
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"clones_dir": {
|
|
14
|
+
"type": "string"
|
|
15
|
+
},
|
|
16
|
+
"patches_dir": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
"ref": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
},
|
|
22
|
+
"verbose": {
|
|
23
|
+
"default": false,
|
|
24
|
+
"type": "boolean"
|
|
25
|
+
},
|
|
26
|
+
"$schema": {
|
|
27
|
+
"type": "string"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"additionalProperties": false
|
|
31
|
+
}
|