git-patch-cli 0.2.0__tar.gz
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.
- git_patch_cli-0.2.0/.gitignore +3 -0
- git_patch_cli-0.2.0/.python-version +1 -0
- git_patch_cli-0.2.0/PKG-INFO +6 -0
- git_patch_cli-0.2.0/README.md +0 -0
- git_patch_cli-0.2.0/design.md +397 -0
- git_patch_cli-0.2.0/design.md.back +277 -0
- git_patch_cli-0.2.0/git_patch_cli/__init__.py +2 -0
- git_patch_cli-0.2.0/git_patch_cli/main.py +225 -0
- git_patch_cli-0.2.0/pyproject.toml +21 -0
- git_patch_cli-0.2.0/uv.lock +97 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.10
|
|
File without changes
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# Git Patch CLI 详细设计文档
|
|
2
|
+
|
|
3
|
+
## 1. 系统概述
|
|
4
|
+
|
|
5
|
+
Git Patch CLI 是一个命令行工具,用于生成 Git 仓库的补丁文件。工具支持增量补丁生成,能够记录每次生成补丁的状态,方便后续继续生成新的补丁。
|
|
6
|
+
|
|
7
|
+
## 1.1 设计原则
|
|
8
|
+
|
|
9
|
+
- **语言无关性**:设计文档中的逻辑和接口定义不依赖于特定编程语言
|
|
10
|
+
- **接口抽象化**:所有外部依赖(如 Git、文件系统)均通过抽象接口访问
|
|
11
|
+
- **可移植性**:核心逻辑应能在不同操作系统(Windows、Linux、macOS)上运行
|
|
12
|
+
- **可扩展性**:支持通过配置文件扩展功能
|
|
13
|
+
|
|
14
|
+
## 1.2 外部依赖
|
|
15
|
+
|
|
16
|
+
| 依赖项 | 类型 | 版本要求 | 说明 |
|
|
17
|
+
|--------|------|----------|------|
|
|
18
|
+
| Git | 命令行工具 | >= 2.0.0 | 用于执行 git format-patch、git rev-parse 等命令 |
|
|
19
|
+
|
|
20
|
+
## 1.3 环境要求
|
|
21
|
+
|
|
22
|
+
| 项目 | 要求 |
|
|
23
|
+
|------|------|
|
|
24
|
+
| 操作系统 | Windows 10+/Linux/macOS |
|
|
25
|
+
| Git 版本 | >= 2.0.0 |
|
|
26
|
+
| 权限 | 读写 source-dir 目录的权限 |
|
|
27
|
+
|
|
28
|
+
## 2. 命令结构
|
|
29
|
+
|
|
30
|
+
### 2.1 patch 命令
|
|
31
|
+
|
|
32
|
+
**功能描述**:基于 Git 仓库生成补丁文件。
|
|
33
|
+
|
|
34
|
+
**参数定义**:
|
|
35
|
+
|
|
36
|
+
| 参数名 | 类型 | 默认值 | 说明 |
|
|
37
|
+
|--------|------|--------|------|
|
|
38
|
+
| --from / -f | 字符串 | "root" | 指定起始 commit id,"root" 表示从根提交开始 |
|
|
39
|
+
| --source-dir | 字符串 | "./" | 指定 Git 仓库路径 |
|
|
40
|
+
| --one-patch | 布尔 | false | 是否只生成一个合并的补丁文件 |
|
|
41
|
+
|
|
42
|
+
## 3. 核心流程
|
|
43
|
+
|
|
44
|
+
### 3.1 流程图
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
开始
|
|
48
|
+
│
|
|
49
|
+
▼
|
|
50
|
+
┌─────────────────────────────┐
|
|
51
|
+
│ 检查 source-dir 是否为 Git │
|
|
52
|
+
│ 仓库(.git 目录是否存在) │
|
|
53
|
+
└─────────────────────────────┘
|
|
54
|
+
│
|
|
55
|
+
├─ 否 ──▶ 输出错误信息,退出
|
|
56
|
+
│
|
|
57
|
+
▼ 是
|
|
58
|
+
┌─────────────────────────────┐
|
|
59
|
+
│ 读取 patch.json 文件 │
|
|
60
|
+
│ (若存在) │
|
|
61
|
+
└─────────────────────────────┘
|
|
62
|
+
│
|
|
63
|
+
├─ 存在 ──▶ 获取 commit_id 和 number
|
|
64
|
+
│
|
|
65
|
+
└─ 不存在 ──▶ 检查 --from 参数
|
|
66
|
+
│
|
|
67
|
+
├─ 为空 ──▶ 输出错误信息,退出
|
|
68
|
+
│
|
|
69
|
+
└─ 不为空 ──▶ 使用 --from 参数作为 commit_id
|
|
70
|
+
│
|
|
71
|
+
▼
|
|
72
|
+
┌─────────────────────────────┐
|
|
73
|
+
│ 获取当前 HEAD 的 commit id │
|
|
74
|
+
└─────────────────────────────┘
|
|
75
|
+
│
|
|
76
|
+
▼
|
|
77
|
+
┌─────────────────────────────┐
|
|
78
|
+
│ 检查是否需要生成补丁 │
|
|
79
|
+
│ (commit_id != "root" 且 │
|
|
80
|
+
│ commit_id == 当前 HEAD) │
|
|
81
|
+
└─────────────────────────────┘
|
|
82
|
+
│
|
|
83
|
+
├─ 是 ──▶ 输出无需生成补丁,退出
|
|
84
|
+
│
|
|
85
|
+
▼ 否
|
|
86
|
+
┌─────────────────────────────┐
|
|
87
|
+
│ number 自增 1 │
|
|
88
|
+
└─────────────────────────────┘
|
|
89
|
+
│
|
|
90
|
+
▼
|
|
91
|
+
┌─────────────────────────────┐
|
|
92
|
+
│ 创建补丁目录 │
|
|
93
|
+
│ .git-patch/patchs/{number} │
|
|
94
|
+
│ (若已存在则删除重建) │
|
|
95
|
+
└─────────────────────────────┘
|
|
96
|
+
│
|
|
97
|
+
▼
|
|
98
|
+
┌─────────────────────────────┐
|
|
99
|
+
│ 执行 git format-patch │
|
|
100
|
+
│ 生成补丁文件 │
|
|
101
|
+
└─────────────────────────────┘
|
|
102
|
+
│
|
|
103
|
+
├─ one-patch=true ──▶ 生成单个 .patch 文件
|
|
104
|
+
│
|
|
105
|
+
└─ one-patch=false ──▶ 生成多个 .patch 文件
|
|
106
|
+
│
|
|
107
|
+
▼
|
|
108
|
+
┌─────────────────────────────┐
|
|
109
|
+
│ 写入 meta.json 元信息文件 │
|
|
110
|
+
└─────────────────────────────┘
|
|
111
|
+
│
|
|
112
|
+
▼
|
|
113
|
+
┌─────────────────────────────┐
|
|
114
|
+
│ 更新 patch.json 状态文件 │
|
|
115
|
+
└─────────────────────────────┘
|
|
116
|
+
│
|
|
117
|
+
▼
|
|
118
|
+
结束
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 4. 数据结构
|
|
122
|
+
|
|
123
|
+
### 4.1 patch.json
|
|
124
|
+
|
|
125
|
+
**文件路径**:`{source-dir}/.git-patch/patch.json`
|
|
126
|
+
|
|
127
|
+
**用途**:记录上次生成补丁的状态,用于增量生成补丁。
|
|
128
|
+
|
|
129
|
+
**结构定义**:
|
|
130
|
+
|
|
131
|
+
| 字段名 | 类型 | 说明 |
|
|
132
|
+
|--------|------|------|
|
|
133
|
+
| commit_id | 字符串 | 上次生成补丁时的目标 commit id |
|
|
134
|
+
| number | 整数 | 补丁序号,从 1 开始递增 |
|
|
135
|
+
|
|
136
|
+
**示例**:
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"commit_id": "83a25860ba12c7a936600f8f10342e946a584f58",
|
|
140
|
+
"number": 3
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 4.2 meta.json
|
|
145
|
+
|
|
146
|
+
**文件路径**:`{source-dir}/.git-patch/patchs/{number}/meta.json`
|
|
147
|
+
|
|
148
|
+
**用途**:记录每个补丁包的元信息。
|
|
149
|
+
|
|
150
|
+
**结构定义**:
|
|
151
|
+
|
|
152
|
+
| 字段名 | 类型 | 说明 |
|
|
153
|
+
|--------|------|------|
|
|
154
|
+
| from_commit_id | 字符串 | 补丁的起始 commit id |
|
|
155
|
+
| to_commit_id | 字符串 | 补丁的目标 commit id |
|
|
156
|
+
| number | 整数 | 补丁序号 |
|
|
157
|
+
|
|
158
|
+
**示例**:
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"from_commit_id": "abc123",
|
|
162
|
+
"to_commit_id": "def456",
|
|
163
|
+
"number": 1
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 5. 目录结构
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
{source-dir}/
|
|
171
|
+
├── .git/ # Git 仓库目录
|
|
172
|
+
└── .git-patch/ # 补丁输出目录
|
|
173
|
+
├── patch.json # 状态文件
|
|
174
|
+
└── patchs/ # 补丁包目录
|
|
175
|
+
├── 0001/ # 第 1 个补丁包
|
|
176
|
+
│ ├── meta.json # 元信息
|
|
177
|
+
│ └── *.patch # 补丁文件(多个或一个)
|
|
178
|
+
├── 0002/ # 第 2 个补丁包
|
|
179
|
+
│ ├── meta.json
|
|
180
|
+
│ └── *.patch
|
|
181
|
+
└── ...
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## 6. 核心逻辑说明
|
|
185
|
+
|
|
186
|
+
### 6.1 Git 仓库检查
|
|
187
|
+
|
|
188
|
+
**逻辑**:检查指定路径下是否存在 `.git` 目录。
|
|
189
|
+
|
|
190
|
+
**失败处理**:若不存在,输出错误信息并退出,退出码为 1。
|
|
191
|
+
|
|
192
|
+
### 6.2 Commit ID 获取策略
|
|
193
|
+
|
|
194
|
+
**优先级**:
|
|
195
|
+
1. **优先读取 patch.json**:若文件存在,读取其中的 `commit_id` 和 `number`
|
|
196
|
+
2. **使用 --from 参数**:若 patch.json 不存在,使用命令行参数 `--from` 指定的 commit id
|
|
197
|
+
3. **默认值**:`--from` 参数的默认值为 "root",表示从根提交开始
|
|
198
|
+
|
|
199
|
+
### 6.3 增量检查
|
|
200
|
+
|
|
201
|
+
**逻辑**:
|
|
202
|
+
- 获取当前 HEAD 的 commit id
|
|
203
|
+
- 如果 `commit_id != "root"` 且 `commit_id == 当前 HEAD`,说明当前已是最新状态,无需生成补丁
|
|
204
|
+
- 输出提示信息并正常退出(非错误退出)
|
|
205
|
+
|
|
206
|
+
### 6.4 补丁序号管理
|
|
207
|
+
|
|
208
|
+
**逻辑**:
|
|
209
|
+
- `number` 从 patch.json 读取(若存在),否则初始为 0
|
|
210
|
+
- 每次生成补丁前,`number` 自增 1
|
|
211
|
+
- 补丁目录格式为 `{number:04d}`,即 4 位数字,不足补零(如 0001, 0002)
|
|
212
|
+
|
|
213
|
+
### 6.5 补丁生成
|
|
214
|
+
|
|
215
|
+
**两种模式**:
|
|
216
|
+
|
|
217
|
+
#### 模式一:单个补丁文件(--one-patch=true)
|
|
218
|
+
|
|
219
|
+
- 使用 `git format-patch {commit_id} --stdout` 或 `git format-patch --root --stdout`
|
|
220
|
+
- 将输出重定向到单个文件 `{number:04d}.patch`
|
|
221
|
+
|
|
222
|
+
#### 模式二:多个补丁文件(--one-patch=false)
|
|
223
|
+
|
|
224
|
+
- 使用 `git format-patch {commit_id} --output-directory {patchs_dir}` 或 `git format-patch --root --output-directory {patchs_dir}`
|
|
225
|
+
- Git 会为每个 commit 生成单独的 `.patch` 文件
|
|
226
|
+
|
|
227
|
+
### 6.6 状态更新
|
|
228
|
+
|
|
229
|
+
**meta.json 更新**:
|
|
230
|
+
- 记录本次补丁的起始 commit id(from_commit_id)
|
|
231
|
+
- 记录本次补丁的目标 commit id(to_commit_id)
|
|
232
|
+
- 记录补丁序号(number)
|
|
233
|
+
|
|
234
|
+
**patch.json 更新**:
|
|
235
|
+
- 更新 commit_id 为当前 HEAD
|
|
236
|
+
- 更新 number 为当前补丁序号
|
|
237
|
+
|
|
238
|
+
## 7. 错误处理
|
|
239
|
+
|
|
240
|
+
### 7.1 Git 命令执行失败
|
|
241
|
+
|
|
242
|
+
**处理方式**:捕获 Git 命令执行错误,输出错误信息,退出码为 1。
|
|
243
|
+
|
|
244
|
+
### 7.2 其他异常
|
|
245
|
+
|
|
246
|
+
**处理方式**:捕获通用异常,输出错误信息,退出码为 1。
|
|
247
|
+
|
|
248
|
+
### 7.3 退出码规范
|
|
249
|
+
|
|
250
|
+
| 退出码 | 含义 | 触发场景 |
|
|
251
|
+
|--------|------|----------|
|
|
252
|
+
| 0 | 成功 | 命令执行成功 |
|
|
253
|
+
| 1 | 错误 | Git 命令执行失败、文件操作失败、参数校验失败 |
|
|
254
|
+
| 2 | 参数错误 | 命令行参数格式错误 |
|
|
255
|
+
|
|
256
|
+
## 7.4 日志规范
|
|
257
|
+
|
|
258
|
+
**输出级别**:
|
|
259
|
+
|
|
260
|
+
| 级别 | 含义 | 使用场景 |
|
|
261
|
+
|------|------|----------|
|
|
262
|
+
| INFO | 信息 | 正常操作的进度提示 |
|
|
263
|
+
| ERROR | 错误 | 命令执行失败时的错误信息 |
|
|
264
|
+
|
|
265
|
+
**输出格式**:
|
|
266
|
+
- 所有输出应写入标准输出(stdout)或标准错误(stderr)
|
|
267
|
+
- 错误信息必须写入 stderr
|
|
268
|
+
|
|
269
|
+
## 8. 接口抽象层
|
|
270
|
+
|
|
271
|
+
为了实现语言无关性,定义以下抽象接口:
|
|
272
|
+
|
|
273
|
+
### 8.1 Git 操作接口
|
|
274
|
+
|
|
275
|
+
| 方法名 | 输入参数 | 返回值 | 说明 |
|
|
276
|
+
|--------|----------|--------|------|
|
|
277
|
+
| `get_current_commit_id(repo_path)` | repo_path: 字符串(Git 仓库路径) | commit_id: 字符串 | 获取当前 HEAD 的 commit id |
|
|
278
|
+
| `generate_patch(repo_path, commit_id, output_dir, one_patch)` | repo_path: 字符串;commit_id: 字符串;output_dir: 字符串;one_patch: 布尔 | 无 | 生成补丁文件 |
|
|
279
|
+
| `generate_single_patch(repo_path, commit_id, output_file)` | repo_path: 字符串;commit_id: 字符串;output_file: 字符串 | 无 | 生成单个补丁文件 |
|
|
280
|
+
|
|
281
|
+
### 8.2 文件系统接口
|
|
282
|
+
|
|
283
|
+
| 方法名 | 输入参数 | 返回值 | 说明 |
|
|
284
|
+
|--------|----------|--------|------|
|
|
285
|
+
| `is_directory(path)` | path: 字符串 | 布尔 | 判断路径是否为目录 |
|
|
286
|
+
| `create_directory(path)` | path: 字符串 | 无 | 创建目录(递归创建) |
|
|
287
|
+
| `delete_directory(path)` | path: 字符串 | 无 | 删除目录及其内容 |
|
|
288
|
+
| `file_exists(path)` | path: 字符串 | 布尔 | 判断文件是否存在 |
|
|
289
|
+
| `read_json(path)` | path: 字符串 | 对象 | 读取 JSON 文件 |
|
|
290
|
+
| `write_json(path, data)` | path: 字符串;data: 对象 | 无 | 写入 JSON 文件 |
|
|
291
|
+
| `write_file(path, content)` | path: 字符串;content: 字符串或二进制 | 无 | 写入文件 |
|
|
292
|
+
|
|
293
|
+
### 8.3 命令行接口
|
|
294
|
+
|
|
295
|
+
| 方法名 | 输入参数 | 返回值 | 说明 |
|
|
296
|
+
|--------|----------|--------|------|
|
|
297
|
+
| `parse_arguments()` | 无 | 参数对象 | 解析命令行参数 |
|
|
298
|
+
| `print_help()` | 无 | 无 | 输出帮助信息 |
|
|
299
|
+
| `print_error(message)` | message: 字符串 | 无 | 输出错误信息到 stderr |
|
|
300
|
+
| `print_info(message)` | message: 字符串 | 无 | 输出信息到 stdout |
|
|
301
|
+
| `exit(code)` | code: 整数 | 无 | 退出程序 |
|
|
302
|
+
|
|
303
|
+
## 9. 边界情况
|
|
304
|
+
|
|
305
|
+
### 9.1 首次使用(patch.json 不存在)
|
|
306
|
+
|
|
307
|
+
**行为**:使用 `--from` 参数指定的 commit id(默认为 "root")。
|
|
308
|
+
|
|
309
|
+
### 9.2 commit_id 为 "root"
|
|
310
|
+
|
|
311
|
+
**行为**:从根提交开始生成补丁,即生成所有 commit 的补丁。
|
|
312
|
+
|
|
313
|
+
### 9.3 当前已是最新状态
|
|
314
|
+
|
|
315
|
+
**行为**:输出提示信息,正常退出,不生成补丁。
|
|
316
|
+
|
|
317
|
+
### 9.4 补丁目录已存在
|
|
318
|
+
|
|
319
|
+
**行为**:先删除已存在的目录,再重新创建。
|
|
320
|
+
|
|
321
|
+
## 10. 命令行接口示例
|
|
322
|
+
|
|
323
|
+
### 10.1 首次生成补丁(从根提交开始)
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
git-patch-cli patch
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### 10.2 首次生成补丁(指定起始 commit)
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
git-patch-cli patch --from abc123
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### 10.3 生成单个补丁文件
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
git-patch-cli patch --one-patch
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 10.4 指定 Git 仓库路径
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
git-patch-cli patch --source-dir /path/to/repo
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### 10.5 增量生成补丁
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
git-patch-cli patch
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
(自动读取上次的 commit_id,生成增量补丁)
|
|
354
|
+
|
|
355
|
+
## 11. 跨语言实现指南
|
|
356
|
+
|
|
357
|
+
### 11.1 通用实现步骤
|
|
358
|
+
|
|
359
|
+
1. **实现接口层**:根据第 8 章定义的接口,实现语言特定的适配器
|
|
360
|
+
2. **实现核心逻辑**:按照第 3 章的流程图实现核心业务逻辑
|
|
361
|
+
3. **实现命令行解析**:使用语言特定的命令行解析库
|
|
362
|
+
4. **实现错误处理**:按照第 7 章的退出码规范处理错误
|
|
363
|
+
5. **编写测试**:覆盖所有边界情况(第 9 章)
|
|
364
|
+
|
|
365
|
+
### 11.2 语言适配示例
|
|
366
|
+
|
|
367
|
+
#### Go 语言
|
|
368
|
+
|
|
369
|
+
| 接口 | Go 实现方式 |
|
|
370
|
+
|------|------------|
|
|
371
|
+
| Git 操作 | 使用 `os/exec` 包执行 git 命令 |
|
|
372
|
+
| 文件系统 | 使用 `os`、`io/ioutil`、`encoding/json` 包 |
|
|
373
|
+
| 命令行解析 | 使用 `flag` 包或第三方库(如 cobra) |
|
|
374
|
+
|
|
375
|
+
#### Node.js
|
|
376
|
+
|
|
377
|
+
| 接口 | Node.js 实现方式 |
|
|
378
|
+
|------|-----------------|
|
|
379
|
+
| Git 操作 | 使用 `child_process` 模块执行 git 命令 |
|
|
380
|
+
| 文件系统 | 使用 `fs`、`path`、`JSON` 模块 |
|
|
381
|
+
| 命令行解析 | 使用第三方库(如 yargs、commander) |
|
|
382
|
+
|
|
383
|
+
#### Java
|
|
384
|
+
|
|
385
|
+
| 接口 | Java 实现方式 |
|
|
386
|
+
|------|--------------|
|
|
387
|
+
| Git 操作 | 使用 `ProcessBuilder` 执行 git 命令,或使用 JGit 库 |
|
|
388
|
+
| 文件系统 | 使用 `java.nio.file`、`com.fasterxml.jackson` |
|
|
389
|
+
| 命令行解析 | 使用 JCommander 或 picocli |
|
|
390
|
+
|
|
391
|
+
#### Rust
|
|
392
|
+
|
|
393
|
+
| 接口 | Rust 实现方式 |
|
|
394
|
+
|------|--------------|
|
|
395
|
+
| Git 操作 | 使用 `std::process::Command` 执行 git 命令 |
|
|
396
|
+
| 文件系统 | 使用 `std::fs`、`serde` + `serde_json` |
|
|
397
|
+
| 命令行解析 | 使用 clap 库 |
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
# Git Patch CLI 详细设计文档
|
|
2
|
+
|
|
3
|
+
## 1. 系统概述
|
|
4
|
+
|
|
5
|
+
Git Patch CLI 是一个命令行工具,用于生成 Git 仓库的补丁文件。工具支持增量补丁生成,能够记录每次生成补丁的状态,方便后续继续生成新的补丁。
|
|
6
|
+
|
|
7
|
+
## 2. 命令结构
|
|
8
|
+
|
|
9
|
+
### 2.1 patch 命令
|
|
10
|
+
|
|
11
|
+
**功能描述**:基于 Git 仓库生成补丁文件。
|
|
12
|
+
|
|
13
|
+
**参数定义**:
|
|
14
|
+
|
|
15
|
+
| 参数名 | 类型 | 默认值 | 说明 |
|
|
16
|
+
|--------|------|--------|------|
|
|
17
|
+
| --from / -f | 字符串 | "root" | 指定起始 commit id,"root" 表示从根提交开始 |
|
|
18
|
+
| --source-dir | 字符串 | "./" | 指定 Git 仓库路径 |
|
|
19
|
+
| --one-patch | 布尔 | false | 是否只生成一个合并的补丁文件 |
|
|
20
|
+
|
|
21
|
+
## 3. 核心流程
|
|
22
|
+
|
|
23
|
+
### 3.1 流程图
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
开始
|
|
27
|
+
│
|
|
28
|
+
▼
|
|
29
|
+
┌─────────────────────────────┐
|
|
30
|
+
│ 检查 source-dir 是否为 Git │
|
|
31
|
+
│ 仓库(.git 目录是否存在) │
|
|
32
|
+
└─────────────────────────────┘
|
|
33
|
+
│
|
|
34
|
+
├─ 否 ──▶ 输出错误信息,退出
|
|
35
|
+
│
|
|
36
|
+
▼ 是
|
|
37
|
+
┌─────────────────────────────┐
|
|
38
|
+
│ 读取 patch.json 文件 │
|
|
39
|
+
│ (若存在) │
|
|
40
|
+
└─────────────────────────────┘
|
|
41
|
+
│
|
|
42
|
+
├─ 存在 ──▶ 获取 commit_id 和 number
|
|
43
|
+
│
|
|
44
|
+
└─ 不存在 ──▶ 检查 --from 参数
|
|
45
|
+
│
|
|
46
|
+
├─ 为空 ──▶ 输出错误信息,退出
|
|
47
|
+
│
|
|
48
|
+
└─ 不为空 ──▶ 使用 --from 参数作为 commit_id
|
|
49
|
+
│
|
|
50
|
+
▼
|
|
51
|
+
┌─────────────────────────────┐
|
|
52
|
+
│ 获取当前 HEAD 的 commit id │
|
|
53
|
+
└─────────────────────────────┘
|
|
54
|
+
│
|
|
55
|
+
▼
|
|
56
|
+
┌─────────────────────────────┐
|
|
57
|
+
│ 检查是否需要生成补丁 │
|
|
58
|
+
│ (commit_id != "root" 且 │
|
|
59
|
+
│ commit_id == 当前 HEAD) │
|
|
60
|
+
└─────────────────────────────┘
|
|
61
|
+
│
|
|
62
|
+
├─ 是 ──▶ 输出无需生成补丁,退出
|
|
63
|
+
│
|
|
64
|
+
▼ 否
|
|
65
|
+
┌─────────────────────────────┐
|
|
66
|
+
│ number 自增 1 │
|
|
67
|
+
└─────────────────────────────┘
|
|
68
|
+
│
|
|
69
|
+
▼
|
|
70
|
+
┌─────────────────────────────┐
|
|
71
|
+
│ 创建补丁目录 │
|
|
72
|
+
│ .git-patch/patchs/{number} │
|
|
73
|
+
│ (若已存在则删除重建) │
|
|
74
|
+
└─────────────────────────────┘
|
|
75
|
+
│
|
|
76
|
+
▼
|
|
77
|
+
┌─────────────────────────────┐
|
|
78
|
+
│ 执行 git format-patch │
|
|
79
|
+
│ 生成补丁文件 │
|
|
80
|
+
└─────────────────────────────┘
|
|
81
|
+
│
|
|
82
|
+
├─ one-patch=true ──▶ 生成单个 .patch 文件
|
|
83
|
+
│
|
|
84
|
+
└─ one-patch=false ──▶ 生成多个 .patch 文件
|
|
85
|
+
│
|
|
86
|
+
▼
|
|
87
|
+
┌─────────────────────────────┐
|
|
88
|
+
│ 写入 meta.json 元信息文件 │
|
|
89
|
+
└─────────────────────────────┘
|
|
90
|
+
│
|
|
91
|
+
▼
|
|
92
|
+
┌─────────────────────────────┐
|
|
93
|
+
│ 更新 patch.json 状态文件 │
|
|
94
|
+
└─────────────────────────────┘
|
|
95
|
+
│
|
|
96
|
+
▼
|
|
97
|
+
结束
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 4. 数据结构
|
|
101
|
+
|
|
102
|
+
### 4.1 patch.json
|
|
103
|
+
|
|
104
|
+
**文件路径**:`{source-dir}/.git-patch/patch.json`
|
|
105
|
+
|
|
106
|
+
**用途**:记录上次生成补丁的状态,用于增量生成补丁。
|
|
107
|
+
|
|
108
|
+
**结构定义**:
|
|
109
|
+
|
|
110
|
+
| 字段名 | 类型 | 说明 |
|
|
111
|
+
|--------|------|------|
|
|
112
|
+
| commit_id | 字符串 | 上次生成补丁时的目标 commit id |
|
|
113
|
+
| number | 整数 | 补丁序号,从 1 开始递增 |
|
|
114
|
+
|
|
115
|
+
**示例**:
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"commit_id": "83a25860ba12c7a936600f8f10342e946a584f58",
|
|
119
|
+
"number": 3
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 4.2 meta.json
|
|
124
|
+
|
|
125
|
+
**文件路径**:`{source-dir}/.git-patch/patchs/{number}/meta.json`
|
|
126
|
+
|
|
127
|
+
**用途**:记录每个补丁包的元信息。
|
|
128
|
+
|
|
129
|
+
**结构定义**:
|
|
130
|
+
|
|
131
|
+
| 字段名 | 类型 | 说明 |
|
|
132
|
+
|--------|------|------|
|
|
133
|
+
| from_commit_id | 字符串 | 补丁的起始 commit id |
|
|
134
|
+
| to_commit_id | 字符串 | 补丁的目标 commit id |
|
|
135
|
+
| number | 整数 | 补丁序号 |
|
|
136
|
+
|
|
137
|
+
**示例**:
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"from_commit_id": "abc123",
|
|
141
|
+
"to_commit_id": "def456",
|
|
142
|
+
"number": 1
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 5. 目录结构
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
{source-dir}/
|
|
150
|
+
├── .git/ # Git 仓库目录
|
|
151
|
+
└── .git-patch/ # 补丁输出目录
|
|
152
|
+
├── patch.json # 状态文件
|
|
153
|
+
└── patchs/ # 补丁包目录
|
|
154
|
+
├── 0001/ # 第 1 个补丁包
|
|
155
|
+
│ ├── meta.json # 元信息
|
|
156
|
+
│ └── *.patch # 补丁文件(多个或一个)
|
|
157
|
+
├── 0002/ # 第 2 个补丁包
|
|
158
|
+
│ ├── meta.json
|
|
159
|
+
│ └── *.patch
|
|
160
|
+
└── ...
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 6. 核心逻辑说明
|
|
164
|
+
|
|
165
|
+
### 6.1 Git 仓库检查
|
|
166
|
+
|
|
167
|
+
**逻辑**:检查指定路径下是否存在 `.git` 目录。
|
|
168
|
+
|
|
169
|
+
**失败处理**:若不存在,输出错误信息并退出,退出码为 1。
|
|
170
|
+
|
|
171
|
+
### 6.2 Commit ID 获取策略
|
|
172
|
+
|
|
173
|
+
**优先级**:
|
|
174
|
+
1. **优先读取 patch.json**:若文件存在,读取其中的 `commit_id` 和 `number`
|
|
175
|
+
2. **使用 --from 参数**:若 patch.json 不存在,使用命令行参数 `--from` 指定的 commit id
|
|
176
|
+
3. **默认值**:`--from` 参数的默认值为 "root",表示从根提交开始
|
|
177
|
+
|
|
178
|
+
### 6.3 增量检查
|
|
179
|
+
|
|
180
|
+
**逻辑**:
|
|
181
|
+
- 获取当前 HEAD 的 commit id
|
|
182
|
+
- 如果 `commit_id != "root"` 且 `commit_id == 当前 HEAD`,说明当前已是最新状态,无需生成补丁
|
|
183
|
+
- 输出提示信息并正常退出(非错误退出)
|
|
184
|
+
|
|
185
|
+
### 6.4 补丁序号管理
|
|
186
|
+
|
|
187
|
+
**逻辑**:
|
|
188
|
+
- `number` 从 patch.json 读取(若存在),否则初始为 0
|
|
189
|
+
- 每次生成补丁前,`number` 自增 1
|
|
190
|
+
- 补丁目录格式为 `{number:04d}`,即 4 位数字,不足补零(如 0001, 0002)
|
|
191
|
+
|
|
192
|
+
### 6.5 补丁生成
|
|
193
|
+
|
|
194
|
+
**两种模式**:
|
|
195
|
+
|
|
196
|
+
#### 模式一:单个补丁文件(--one-patch=true)
|
|
197
|
+
|
|
198
|
+
- 使用 `git format-patch {commit_id} --stdout` 或 `git format-patch --root --stdout`
|
|
199
|
+
- 将输出重定向到单个文件 `{number:04d}.patch`
|
|
200
|
+
|
|
201
|
+
#### 模式二:多个补丁文件(--one-patch=false)
|
|
202
|
+
|
|
203
|
+
- 使用 `git format-patch {commit_id} --output-directory {patchs_dir}` 或 `git format-patch --root --output-directory {patchs_dir}`
|
|
204
|
+
- Git 会为每个 commit 生成单独的 `.patch` 文件
|
|
205
|
+
|
|
206
|
+
### 6.6 状态更新
|
|
207
|
+
|
|
208
|
+
**meta.json 更新**:
|
|
209
|
+
- 记录本次补丁的起始 commit id(from_commit_id)
|
|
210
|
+
- 记录本次补丁的目标 commit id(to_commit_id)
|
|
211
|
+
- 记录补丁序号(number)
|
|
212
|
+
|
|
213
|
+
**patch.json 更新**:
|
|
214
|
+
- 更新 commit_id 为当前 HEAD
|
|
215
|
+
- 更新 number 为当前补丁序号
|
|
216
|
+
|
|
217
|
+
## 7. 错误处理
|
|
218
|
+
|
|
219
|
+
### 7.1 Git 命令执行失败
|
|
220
|
+
|
|
221
|
+
**处理方式**:捕获 Git 命令执行错误,输出错误信息,退出码为 1。
|
|
222
|
+
|
|
223
|
+
### 7.2 其他异常
|
|
224
|
+
|
|
225
|
+
**处理方式**:捕获通用异常,输出错误信息,退出码为 1。
|
|
226
|
+
|
|
227
|
+
## 8. 边界情况
|
|
228
|
+
|
|
229
|
+
### 8.1 首次使用(patch.json 不存在)
|
|
230
|
+
|
|
231
|
+
**行为**:使用 `--from` 参数指定的 commit id(默认为 "root")。
|
|
232
|
+
|
|
233
|
+
### 8.2 commit_id 为 "root"
|
|
234
|
+
|
|
235
|
+
**行为**:从根提交开始生成补丁,即生成所有 commit 的补丁。
|
|
236
|
+
|
|
237
|
+
### 8.3 当前已是最新状态
|
|
238
|
+
|
|
239
|
+
**行为**:输出提示信息,正常退出,不生成补丁。
|
|
240
|
+
|
|
241
|
+
### 8.4 补丁目录已存在
|
|
242
|
+
|
|
243
|
+
**行为**:先删除已存在的目录,再重新创建。
|
|
244
|
+
|
|
245
|
+
## 9. 命令行接口示例
|
|
246
|
+
|
|
247
|
+
### 9.1 首次生成补丁(从根提交开始)
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
git-patch-cli patch
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 9.2 首次生成补丁(指定起始 commit)
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
git-patch-cli patch --from abc123
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### 9.3 生成单个补丁文件
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
git-patch-cli patch --one-patch
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 9.4 指定 Git 仓库路径
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
git-patch-cli patch --source-dir /path/to/repo
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### 9.5 增量生成补丁
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
git-patch-cli patch
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
(自动读取上次的 commit_id,生成增量补丁)
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
import subprocess
|
|
3
|
+
import os
|
|
4
|
+
import json
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import glob
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
app = typer.Typer(help="Git Patch CLI - A tool to generate and apply patches")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@app.command(help="Generate a patch using git format-patch")
|
|
14
|
+
def patch(
|
|
15
|
+
from_commit: str = typer.Option("root", "--from", "-f", help="指定 commit id"),
|
|
16
|
+
source_dir:str = typer.Option("./", "--source-dir", help="指定 git repo 路径"),
|
|
17
|
+
one_patch:bool = typer.Option("false", "--one-patch", help="只生成一个 patch 文件")
|
|
18
|
+
):
|
|
19
|
+
try:
|
|
20
|
+
git_dir = os.path.join(source_dir, ".git")
|
|
21
|
+
if not os.path.isdir(git_dir):
|
|
22
|
+
typer.echo(f"Error: {source_dir} is not a git repository", err=True)
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
source_dir = os.path.abspath(source_dir)
|
|
26
|
+
output_dir = os.path.join(source_dir, ".git-patch")
|
|
27
|
+
patch_json_path = os.path.join(output_dir, "patch.json")
|
|
28
|
+
|
|
29
|
+
commit_id = None
|
|
30
|
+
number:int = 0
|
|
31
|
+
|
|
32
|
+
if os.path.exists(patch_json_path):
|
|
33
|
+
with open(patch_json_path, "r") as f:
|
|
34
|
+
data = json.load(f)
|
|
35
|
+
commit_id = data.get("commit_id", None)
|
|
36
|
+
number = data.get("number", number)
|
|
37
|
+
typer.echo(f"Using commit id from patch.json: {commit_id}")
|
|
38
|
+
else:
|
|
39
|
+
if from_commit is None:
|
|
40
|
+
typer.echo("Error: patch.json not found and --from argument is not provided", err=True)
|
|
41
|
+
return
|
|
42
|
+
commit_id = from_commit
|
|
43
|
+
typer.echo(f"Using commit id from --from argument: {commit_id}")
|
|
44
|
+
|
|
45
|
+
result = subprocess.run(
|
|
46
|
+
["git", "rev-parse", "HEAD"],
|
|
47
|
+
check=True,
|
|
48
|
+
capture_output=True,
|
|
49
|
+
text=True
|
|
50
|
+
)
|
|
51
|
+
current_commit_id = result.stdout.strip()
|
|
52
|
+
if commit_id != "root":
|
|
53
|
+
if commit_id == current_commit_id:
|
|
54
|
+
typer.echo(f"{commit_id} 已经是最新的提交记录,无需生成补丁")
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
number += 1
|
|
58
|
+
|
|
59
|
+
patchs_dir = os.path.join(output_dir, "patchs", f"{number:04d}")
|
|
60
|
+
if os.path.isdir(patchs_dir):
|
|
61
|
+
shutil.rmtree(patchs_dir)
|
|
62
|
+
|
|
63
|
+
os.makedirs(patchs_dir, exist_ok=True)
|
|
64
|
+
|
|
65
|
+
if one_patch:
|
|
66
|
+
out_file_path = os.path.join(patchs_dir, f"{number:04d}.patch")
|
|
67
|
+
cmd = [
|
|
68
|
+
"git", "format-patch", f"{commit_id}", "--stdout"
|
|
69
|
+
]
|
|
70
|
+
if commit_id == "root":
|
|
71
|
+
cmd = [
|
|
72
|
+
"git", "format-patch", "--root", "--stdout"
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
with open(out_file_path, "w") as f:
|
|
76
|
+
subprocess.run(
|
|
77
|
+
cmd,
|
|
78
|
+
check=True,
|
|
79
|
+
#capture_output=True,
|
|
80
|
+
#text=True,
|
|
81
|
+
cwd=source_dir,
|
|
82
|
+
stdout=f,
|
|
83
|
+
)
|
|
84
|
+
else:
|
|
85
|
+
cmd = [
|
|
86
|
+
"git", "format-patch", f"{commit_id}",
|
|
87
|
+
"--output-directory", patchs_dir
|
|
88
|
+
]
|
|
89
|
+
if commit_id == "root":
|
|
90
|
+
cmd = [
|
|
91
|
+
"git", "format-patch", "--root",
|
|
92
|
+
"--output-directory", patchs_dir
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
typer.echo(f"执行命令: {cmd}")
|
|
96
|
+
subprocess.run(
|
|
97
|
+
cmd,
|
|
98
|
+
check=True,
|
|
99
|
+
#capture_output=True,
|
|
100
|
+
#text=True,
|
|
101
|
+
cwd=source_dir,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
meta_file_path = os.path.join(patchs_dir, "meta.json")
|
|
105
|
+
with open(meta_file_path, "w") as f:
|
|
106
|
+
m = {
|
|
107
|
+
"from_commit_id": commit_id,
|
|
108
|
+
"to_commit_id": current_commit_id,
|
|
109
|
+
"number": number,
|
|
110
|
+
}
|
|
111
|
+
json.dump(m, f, indent=2)
|
|
112
|
+
|
|
113
|
+
with open(patch_json_path, "w") as f:
|
|
114
|
+
m = {
|
|
115
|
+
"commit_id": current_commit_id,
|
|
116
|
+
"number": number
|
|
117
|
+
}
|
|
118
|
+
json.dump(m, f, indent=2)
|
|
119
|
+
|
|
120
|
+
typer.echo(f"Patch generated successfully in '{output_dir}'")
|
|
121
|
+
typer.echo(f"Commit id: {commit_id}")
|
|
122
|
+
typer.echo(f"Number: {number}")
|
|
123
|
+
typer.echo(f"patch.json written to '{patch_json_path}'")
|
|
124
|
+
|
|
125
|
+
except subprocess.CalledProcessError as e:
|
|
126
|
+
typer.echo(f"Error executing git command: {e.stderr}", err=True)
|
|
127
|
+
raise typer.Exit(code=1)
|
|
128
|
+
except Exception as e:
|
|
129
|
+
typer.echo(f"Error: {str(e)}", err=True)
|
|
130
|
+
raise typer.Exit(code=1)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# @app.command(help="Apply a patch to target")
|
|
134
|
+
# def apply(
|
|
135
|
+
# patch_file: str = typer.Option(..., "--patch", "-p", help="Patch file to apply"),
|
|
136
|
+
# target: str = typer.Option(".", "--target", "-t", help="Target directory or file")
|
|
137
|
+
# ):
|
|
138
|
+
# typer.echo(f"Applying patch '{patch_file}' to '{target}'...")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@app.command(help="apply all patch to target")
|
|
142
|
+
def apply_all(
|
|
143
|
+
source_dir:str = typer.Option("./", "--source-dir", help="指定 git repo 路径"),
|
|
144
|
+
apply_patch_dir: str = typer.Option(..., "--patch-dir", "-p", help="Patch file to apply"),
|
|
145
|
+
):
|
|
146
|
+
source_dir = os.path.abspath(source_dir)
|
|
147
|
+
apply_patch_dir = os.path.abspath(apply_patch_dir)
|
|
148
|
+
|
|
149
|
+
git_dir = os.path.join(source_dir, ".git")
|
|
150
|
+
if not os.path.isdir(git_dir):
|
|
151
|
+
typer.echo(f"Error: {source_dir} is not a git repository", err=True)
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
if not os.path.isdir(apply_patch_dir):
|
|
155
|
+
typer.echo(f"Error: {apply_patch_dir} 不是一个目录", err=True)
|
|
156
|
+
return
|
|
157
|
+
|
|
158
|
+
meta_file_path = os.path.join(apply_patch_dir, "meta.json")
|
|
159
|
+
if not os.path.isfile(meta_file_path):
|
|
160
|
+
typer.echo(f"Error: {apply_patch_dir} 不是一个有效的 patch 目录", err=True)
|
|
161
|
+
return
|
|
162
|
+
|
|
163
|
+
patch_file_list = glob.glob("*.patch", root_dir=apply_patch_dir)
|
|
164
|
+
if len(patch_file_list) == 0:
|
|
165
|
+
typer.echo(f"Error: {apply_patch_dir} 不是一个有效的 patch 目录", err=True)
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
cmd = ["git", "diff", "--name-only"]
|
|
169
|
+
result = subprocess.check_output(cmd, cwd=source_dir)
|
|
170
|
+
if result:
|
|
171
|
+
typer.echo("有文件被修改过,请先提交,再 apply patch")
|
|
172
|
+
return
|
|
173
|
+
|
|
174
|
+
from_commit_id = ""
|
|
175
|
+
to_commit_id = ""
|
|
176
|
+
with open(meta_file_path, "r") as f:
|
|
177
|
+
data = json.load(f)
|
|
178
|
+
from_commit_id = data.get("from_commit_id", "")
|
|
179
|
+
to_commit_id = data.get("to_commit_id", "")
|
|
180
|
+
|
|
181
|
+
git_patch_dir = os.path.join(source_dir, ".git-patch")
|
|
182
|
+
apply_json_file = os.path.join(git_patch_dir, "apply.json")
|
|
183
|
+
if os.path.isfile(apply_json_file):
|
|
184
|
+
with open(apply_json_file, "r") as f:
|
|
185
|
+
data = json.load(f)
|
|
186
|
+
commit_id = data.get("apply_commit_id", "")
|
|
187
|
+
if commit_id != from_commit_id:
|
|
188
|
+
typer.echo("上次 apply 的commit id 不一致,拒绝 apply patch", err=True)
|
|
189
|
+
return
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
for i in range(1, len(patch_file_list)+1):
|
|
193
|
+
patch_file_path = os.path.join(apply_patch_dir, f"{i:04d}.patch")
|
|
194
|
+
if not os.path.isfile(patch_file_path):
|
|
195
|
+
file_list = glob.glob(f"{i:04d}-*.patch", root_dir=apply_patch_dir)
|
|
196
|
+
if len(file_list) == 0:
|
|
197
|
+
typer.echo(f"没有找到 {i:04d} patch 文件", err=True)
|
|
198
|
+
return
|
|
199
|
+
name = file_list[0]
|
|
200
|
+
patch_file_path = os.path.join(apply_patch_dir, name)
|
|
201
|
+
|
|
202
|
+
cmd = ["git", "apply", patch_file_path]
|
|
203
|
+
typer.echo(f"开始 apply patch {patch_file_path}")
|
|
204
|
+
subprocess.check_call(cmd, cwd=source_dir)
|
|
205
|
+
typer.echo(f"完成 apply patch {patch_file_path}")
|
|
206
|
+
|
|
207
|
+
except Exception as e:
|
|
208
|
+
typer.echo(f"Error: {str(e)}", err=True)
|
|
209
|
+
typer.echo("apply patch 发生异常,回滚仓库")
|
|
210
|
+
cmd = ["git", "checkout", "."]
|
|
211
|
+
subprocess.check_call(cmd, cwd=source_dir)
|
|
212
|
+
raise typer.Exit(code=1)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
os.makedirs(git_patch_dir, exist_ok=True)
|
|
216
|
+
|
|
217
|
+
with open(apply_json_file, "w") as f:
|
|
218
|
+
m = {
|
|
219
|
+
"apply_commit_id":to_commit_id
|
|
220
|
+
}
|
|
221
|
+
json.dump(m, f, indent=2)
|
|
222
|
+
typer.echo(f"完成 apply {apply_patch_dir}")
|
|
223
|
+
|
|
224
|
+
if __name__ == "__main__":
|
|
225
|
+
app()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", ]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "git-patch-cli"
|
|
7
|
+
description = "Add your description here"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = ["typer>=0.9.0"]
|
|
11
|
+
dynamic = ["version"]
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
git-patch-cli = "git_patch_cli.main:app"
|
|
15
|
+
|
|
16
|
+
[tool.hatch.version]
|
|
17
|
+
path = "git_patch_cli/__init__.py"
|
|
18
|
+
|
|
19
|
+
[tool.ty.environment]
|
|
20
|
+
root = ["./git_patch_cli"]
|
|
21
|
+
extra-paths = ["./"]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
version = 1
|
|
2
|
+
requires-python = ">=3.10"
|
|
3
|
+
|
|
4
|
+
[[package]]
|
|
5
|
+
name = "annotated-doc"
|
|
6
|
+
version = "0.0.4"
|
|
7
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
8
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/57/ba/046ceea27344560984e26a590f90bc7f4a75b06701f653222458922b558c/annotated_doc-0.0.4.tar.gz", hash = "sha256:fbcda96e87e9c92ad167c2e53839e57503ecfda18804ea28102353485033faa4" }
|
|
9
|
+
wheels = [
|
|
10
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/1e/d3/26bf1008eb3d2daa8ef4cacc7f3bfdc11818d111f7e2d0201bc6e3b49d45/annotated_doc-0.0.4-py3-none-any.whl", hash = "sha256:571ac1dc6991c450b25a9c2d84a3705e2ae7a53467b5d111c24fa8baabbed320" },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[[package]]
|
|
14
|
+
name = "colorama"
|
|
15
|
+
version = "0.4.6"
|
|
16
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
17
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44" }
|
|
18
|
+
wheels = [
|
|
19
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" },
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[[package]]
|
|
23
|
+
name = "git-patch-cli"
|
|
24
|
+
source = { editable = "." }
|
|
25
|
+
dependencies = [
|
|
26
|
+
{ name = "typer" },
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[package.metadata]
|
|
30
|
+
requires-dist = [{ name = "typer", specifier = ">=0.9.0" }]
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "markdown-it-py"
|
|
34
|
+
version = "4.2.0"
|
|
35
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
36
|
+
dependencies = [
|
|
37
|
+
{ name = "mdurl" },
|
|
38
|
+
]
|
|
39
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/06/ff/7841249c247aa650a76b9ee4bbaeae59370dc8bfd2f6c01f3630c35eb134/markdown_it_py-4.2.0.tar.gz", hash = "sha256:04a21681d6fbb623de53f6f364d352309d4094dd4194040a10fd51833e418d49" }
|
|
40
|
+
wheels = [
|
|
41
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/b3/81/4da04ced5a082363ecfa159c010d200ecbd959ae410c10c0264a38cac0f5/markdown_it_py-4.2.0-py3-none-any.whl", hash = "sha256:9f7ebbcd14fe59494226453aed97c1070d83f8d24b6fc3a3bcf9a38092641c4a" },
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[[package]]
|
|
45
|
+
name = "mdurl"
|
|
46
|
+
version = "0.1.2"
|
|
47
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
48
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba" }
|
|
49
|
+
wheels = [
|
|
50
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8" },
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[[package]]
|
|
54
|
+
name = "pygments"
|
|
55
|
+
version = "2.20.0"
|
|
56
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
57
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f" }
|
|
58
|
+
wheels = [
|
|
59
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176" },
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[[package]]
|
|
63
|
+
name = "rich"
|
|
64
|
+
version = "15.0.0"
|
|
65
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
66
|
+
dependencies = [
|
|
67
|
+
{ name = "markdown-it-py" },
|
|
68
|
+
{ name = "pygments" },
|
|
69
|
+
]
|
|
70
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/c0/8f/0722ca900cc807c13a6a0c696dacf35430f72e0ec571c4275d2371fca3e9/rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36" }
|
|
71
|
+
wheels = [
|
|
72
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb" },
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
[[package]]
|
|
76
|
+
name = "shellingham"
|
|
77
|
+
version = "1.5.4"
|
|
78
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
79
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de" }
|
|
80
|
+
wheels = [
|
|
81
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686" },
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "typer"
|
|
86
|
+
version = "0.26.7"
|
|
87
|
+
source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }
|
|
88
|
+
dependencies = [
|
|
89
|
+
{ name = "annotated-doc" },
|
|
90
|
+
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
|
91
|
+
{ name = "rich" },
|
|
92
|
+
{ name = "shellingham" },
|
|
93
|
+
]
|
|
94
|
+
sdist = { url = "https://mirrors.aliyun.com/pypi/packages/5e/ed/ef06584ccdd5c410df0837951ecd7e15d9a6144ea1bd4c73cecab1a89891/typer-0.26.7.tar.gz", hash = "sha256:e314a34c617e419c091b2830dda3ea1f257134ff593061a8f5b9717ab8dddb3a" }
|
|
95
|
+
wheels = [
|
|
96
|
+
{ url = "https://mirrors.aliyun.com/pypi/packages/24/25/2201973529af2c954de0bb725323c3aaed6d7f0ceee8f550dec9185df013/typer-0.26.7-py3-none-any.whl", hash = "sha256:5c87cfbc5d34491c5346ebf49c23e18d56ccb863268d3a8d592b26087c2f5e58" },
|
|
97
|
+
]
|