@done-coding/cli-git 0.6.10 → 0.6.12
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 +333 -5
- package/es/cli.mjs +2 -2
- package/es/helpers.mjs +16 -16
- package/es/{index-c708b569.js → index-166c6260.js} +1 -1
- package/es/{index-85cc6959.js → index-8640f971.js} +1 -1
- package/es/index.mjs +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,11 +1,339 @@
|
|
|
1
1
|
# @done-coding/cli-git
|
|
2
2
|
|
|
3
|
+
git 跨平台操作命令行工具 - 提供 git 平台克隆、钩子管理和检查功能
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@done-coding/cli-git)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
### 独立安装
|
|
11
|
+
```bash
|
|
12
|
+
npm install @done-coding/cli-git
|
|
13
|
+
# 或
|
|
14
|
+
pnpm add @done-coding/cli-git
|
|
3
15
|
```
|
|
4
|
-
|
|
16
|
+
|
|
17
|
+
### 作为 done-coding CLI 的一部分
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @done-coding/cli
|
|
20
|
+
# 然后使用
|
|
21
|
+
DC git [command] # macOS/Linux
|
|
22
|
+
dc git [command] # Windows
|
|
5
23
|
```
|
|
6
24
|
|
|
7
|
-
##
|
|
25
|
+
## 快速开始
|
|
8
26
|
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
27
|
+
```bash
|
|
28
|
+
# 独立使用
|
|
29
|
+
dc-git --help
|
|
30
|
+
|
|
31
|
+
# 作为主 CLI 的子命令
|
|
32
|
+
DC git --help # macOS/Linux
|
|
33
|
+
dc git --help # Windows
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 功能特性
|
|
37
|
+
|
|
38
|
+
- ✅ **平台克隆**: 支持从 GitHub、GitLab 等平台快速克隆用户仓库
|
|
39
|
+
- 🔧 **配置管理**: 初始化和管理 git 相关配置文件
|
|
40
|
+
- 🪝 **钩子支持**: 提供 git 钩子的回调和管理功能
|
|
41
|
+
- 🔍 **状态检查**: 检查 git 操作和仓库状态
|
|
42
|
+
|
|
43
|
+
## API 文档
|
|
44
|
+
|
|
45
|
+
### 基础命令
|
|
46
|
+
|
|
47
|
+
#### `dc-git init`
|
|
48
|
+
初始化配置文件
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
dc-git init
|
|
52
|
+
# 创建 git 相关的配置文件
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### `dc-git clone <platform> <username>`
|
|
56
|
+
从指定的 git 平台克隆用户的代码仓库
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# 从 GitHub 克隆用户仓库
|
|
60
|
+
dc-git clone github username
|
|
61
|
+
|
|
62
|
+
# 从 GitLab 克隆用户仓库
|
|
63
|
+
dc-git clone gitlab username
|
|
64
|
+
|
|
65
|
+
# 从其他平台克隆
|
|
66
|
+
dc-git clone bitbucket username
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**参数说明**:
|
|
70
|
+
- `platform`: git 平台名称 (github, gitlab, bitbucket 等)
|
|
71
|
+
- `username`: 用户名
|
|
72
|
+
|
|
73
|
+
#### `dc-git hooks <name> [args...]`
|
|
74
|
+
执行 git 钩子回调
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 执行 pre-commit 钩子
|
|
78
|
+
dc-git hooks pre-commit
|
|
79
|
+
|
|
80
|
+
# 执行 post-commit 钩子
|
|
81
|
+
dc-git hooks post-commit
|
|
82
|
+
|
|
83
|
+
# 带参数执行钩子
|
|
84
|
+
dc-git hooks pre-push origin main
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**参数说明**:
|
|
88
|
+
- `name`: 钩子名称
|
|
89
|
+
- `args`: 传递给钩子的参数
|
|
90
|
+
|
|
91
|
+
#### `dc-git check <type>`
|
|
92
|
+
检查 git 操作和状态,主要为工程化配置提供支持
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 检测反向合并(为 dc-config 的 merge-lint 模块提供支持)
|
|
96
|
+
dc-git check reverse-merge
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**参数说明**:
|
|
100
|
+
- `type`: 检查类型
|
|
101
|
+
- `reverse-merge`: 检测反向合并,防止高级分支被合并到低级分支
|
|
102
|
+
|
|
103
|
+
**功能说明**:
|
|
104
|
+
此命令主要为 `@done-coding/cli-config` 包的 `merge-lint` 模块提供 git 合并规范检测功能,确保团队遵循正确的分支合并方向。
|
|
105
|
+
|
|
106
|
+
## 使用示例
|
|
107
|
+
|
|
108
|
+
### 基础使用场景
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 1. 初始化配置
|
|
112
|
+
dc-git init
|
|
113
|
+
|
|
114
|
+
# 2. 从 Gitee 克隆用户的所有仓库
|
|
115
|
+
dc-git clone gitee username
|
|
116
|
+
|
|
117
|
+
# 3. 检查反向合并(通常由 dc-config 自动调用)
|
|
118
|
+
dc-git check reverse-merge
|
|
119
|
+
|
|
120
|
+
# 4. 执行 git 钩子
|
|
121
|
+
dc-git hooks pre-commit
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 集成到工程化配置
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# dc-config 包会自动调用 git 检测功能
|
|
128
|
+
dc-config check
|
|
129
|
+
|
|
130
|
+
# 如果启用了 merge-lint 模块,会自动执行:
|
|
131
|
+
# dc-git check reverse-merge
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 作为主 CLI 的一部分
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Windows 系统
|
|
138
|
+
dc git init
|
|
139
|
+
dc git clone gitee username
|
|
140
|
+
dc git hooks pre-commit
|
|
141
|
+
dc git check reverse-merge
|
|
142
|
+
|
|
143
|
+
# macOS/Linux 系统
|
|
144
|
+
DC git init
|
|
145
|
+
DC git clone gitee username
|
|
146
|
+
DC git hooks pre-commit
|
|
147
|
+
DC git check reverse-merge
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## 配置
|
|
151
|
+
|
|
152
|
+
在项目根目录创建 `.done-coding-git.config.js`:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
export default {
|
|
156
|
+
// 默认平台
|
|
157
|
+
defaultPlatform: 'github',
|
|
158
|
+
|
|
159
|
+
// 克隆配置
|
|
160
|
+
clone: {
|
|
161
|
+
// 默认克隆协议
|
|
162
|
+
protocol: 'https', // 或 'ssh'
|
|
163
|
+
// 目标目录
|
|
164
|
+
targetDir: './repos'
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
// 钩子配置
|
|
168
|
+
hooks: {
|
|
169
|
+
// 启用的钩子
|
|
170
|
+
enabled: ['pre-commit', 'post-commit', 'pre-push'],
|
|
171
|
+
// 钩子脚本路径
|
|
172
|
+
scriptsPath: './.git/hooks'
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// 检查配置
|
|
176
|
+
check: {
|
|
177
|
+
// 默认检查项
|
|
178
|
+
defaultChecks: ['status', 'branch', 'remote']
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 编程接口
|
|
184
|
+
|
|
185
|
+
### 作为模块使用
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
import { GitHelper } from '@done-coding/cli-git/helpers';
|
|
189
|
+
|
|
190
|
+
const git = new GitHelper();
|
|
191
|
+
|
|
192
|
+
// 克隆仓库
|
|
193
|
+
await git.cloneFromPlatform('github', 'username');
|
|
194
|
+
|
|
195
|
+
// 执行钩子
|
|
196
|
+
await git.executeHook('pre-commit', []);
|
|
197
|
+
|
|
198
|
+
// 检查状态
|
|
199
|
+
const status = await git.checkStatus('status');
|
|
200
|
+
console.log(status);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### TypeScript 支持
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import type { PlatformType, HookType, CheckType } from '@done-coding/cli-git/helpers';
|
|
207
|
+
|
|
208
|
+
const platform: PlatformType = 'github';
|
|
209
|
+
const hook: HookType = 'pre-commit';
|
|
210
|
+
const checkType: CheckType = 'status';
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 故障排除
|
|
214
|
+
|
|
215
|
+
### 常见问题
|
|
216
|
+
|
|
217
|
+
**Q: 克隆失败**
|
|
218
|
+
```bash
|
|
219
|
+
# 检查网络连接
|
|
220
|
+
ping github.com
|
|
221
|
+
|
|
222
|
+
# 检查 git 配置
|
|
223
|
+
git config --list
|
|
224
|
+
|
|
225
|
+
# 使用详细模式查看错误
|
|
226
|
+
dc-git clone github username --verbose
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Q: 钩子执行失败**
|
|
230
|
+
```bash
|
|
231
|
+
# 检查钩子文件权限
|
|
232
|
+
ls -la .git/hooks/
|
|
233
|
+
|
|
234
|
+
# 手动执行钩子测试
|
|
235
|
+
.git/hooks/pre-commit
|
|
236
|
+
|
|
237
|
+
# 重新初始化钩子
|
|
238
|
+
dc-git init
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Q: 检查命令无响应**
|
|
242
|
+
```bash
|
|
243
|
+
# 确保在 git 仓库中
|
|
244
|
+
git status
|
|
245
|
+
|
|
246
|
+
# 检查仓库完整性
|
|
247
|
+
git fsck
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### 调试模式
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# 启用详细输出
|
|
254
|
+
dc-git --verbose check status
|
|
255
|
+
|
|
256
|
+
# 启用调试模式
|
|
257
|
+
DEBUG=done-coding:git dc-git clone github username
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## 性能建议
|
|
261
|
+
|
|
262
|
+
- 对于大量仓库克隆,建议分批进行
|
|
263
|
+
- 使用 SSH 协议可以提高克隆速度
|
|
264
|
+
- 定期清理无用的配置文件
|
|
265
|
+
|
|
266
|
+
## 贡献指南
|
|
267
|
+
|
|
268
|
+
我们欢迎贡献!请遵循以下步骤:
|
|
269
|
+
|
|
270
|
+
1. Fork 本仓库
|
|
271
|
+
2. 创建功能分支:`git checkout -b feature/amazing-feature`
|
|
272
|
+
3. 提交更改:`git commit -m "feat: add amazing feature"`
|
|
273
|
+
4. 推送分支:`git push origin feature/amazing-feature`
|
|
274
|
+
5. 创建 Pull Request
|
|
275
|
+
|
|
276
|
+
### 开发环境设置
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# 克隆仓库
|
|
280
|
+
git clone https://gitee.com/done-coding/done-coding-cli.git
|
|
281
|
+
cd done-coding-cli/packages/git
|
|
282
|
+
|
|
283
|
+
# 安装依赖
|
|
284
|
+
pnpm install
|
|
285
|
+
|
|
286
|
+
# 开发模式
|
|
287
|
+
pnpm dev
|
|
288
|
+
|
|
289
|
+
# 构建
|
|
290
|
+
pnpm build
|
|
291
|
+
|
|
292
|
+
# 本地开发测试
|
|
293
|
+
node es/cli.mjs --help
|
|
294
|
+
|
|
295
|
+
# 注意:本地使用 node + 入口文件,发布后使用 bin 命令名
|
|
296
|
+
# 功能完全一致,只是调用方式不同
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## 许可证
|
|
300
|
+
|
|
301
|
+
MIT © [JustSoSu](https://gitee.com/done-coding)
|
|
302
|
+
|
|
303
|
+
## 包依赖关系
|
|
304
|
+
|
|
305
|
+
### 为其他包提供服务
|
|
306
|
+
|
|
307
|
+
`@done-coding/cli-git` 的 `check` 命令专门为 `@done-coding/cli-config` 包提供 git 合并检测功能:
|
|
308
|
+
|
|
309
|
+
- **merge-lint 模块**: `dc-config` 包的 `merge-lint` 配置模块依赖 `dc-git check reverse-merge` 命令
|
|
310
|
+
- **反向合并检测**: 防止将高级分支(如 main/master)合并到低级分支(如 feature/develop)
|
|
311
|
+
- **集成使用**: 当 `dc-config` 检测工程化配置时,会调用 `dc-git check` 来验证 git 合并规范
|
|
312
|
+
|
|
313
|
+
### 检测功能详解
|
|
314
|
+
|
|
315
|
+
#### `dc-git check reverse-merge`
|
|
316
|
+
专为工程化配置提供的 git 合并规范检测:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
# 检测当前分支是否存在反向合并
|
|
320
|
+
dc-git check reverse-merge
|
|
321
|
+
|
|
322
|
+
# 该命令会检测:
|
|
323
|
+
# 1. 通过 git reflog 检测合并操作
|
|
324
|
+
# 2. 通过提交信息检测合并记录
|
|
325
|
+
# 3. 通过提交记录检测历史合并
|
|
326
|
+
# 4. 检测 rebase 操作的合规性
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**检测场景**:
|
|
330
|
+
- 防止 `main` 分支被合并到 `feature` 分支
|
|
331
|
+
- 防止 `develop` 分支被合并到个人开发分支
|
|
332
|
+
- 确保分支合并方向符合 Git Flow 规范
|
|
333
|
+
|
|
334
|
+
## 相关链接
|
|
335
|
+
|
|
336
|
+
- [主 CLI 工具](https://www.npmjs.com/package/@done-coding/cli)
|
|
337
|
+
- [配置工具包](https://www.npmjs.com/package/@done-coding/cli-config) - 使用本包的检测功能
|
|
338
|
+
- [Gitee 仓库](https://gitee.com/done-coding/done-coding-cli)
|
|
339
|
+
- [更新日志](./CHANGELOG.md)
|
package/es/cli.mjs
CHANGED
package/es/helpers.mjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { g as
|
|
3
|
-
import { xPrompts as
|
|
2
|
+
import { g as i, G as r, a as m, h as s } from "./index-8640f971.js";
|
|
3
|
+
import { log as o, xPrompts as n } from "@done-coding/cli-utils";
|
|
4
4
|
import "node:child_process";
|
|
5
5
|
import "node:fs";
|
|
6
6
|
import "node:path";
|
|
7
7
|
import "@done-coding/request-axios";
|
|
8
8
|
import "axios";
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const { platform:
|
|
12
|
-
|
|
13
|
-
const { username:
|
|
14
|
-
|
|
9
|
+
const G = async (e) => {
|
|
10
|
+
o.info("克隆done-coding系列项目"), o.stage("选择平台:");
|
|
11
|
+
const { platform: t } = await n(i(r.GITEE));
|
|
12
|
+
o.stage("选择用户名:");
|
|
13
|
+
const { username: a } = await n(
|
|
14
|
+
m(
|
|
15
15
|
{
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
}[
|
|
16
|
+
[r.GITHUB]: "done-coding",
|
|
17
|
+
[r.GITEE]: "justsosu"
|
|
18
|
+
}[t]
|
|
19
19
|
)
|
|
20
20
|
);
|
|
21
|
-
|
|
22
|
-
platform:
|
|
23
|
-
username:
|
|
24
|
-
projectName:
|
|
21
|
+
o.info("platform:", t), o.info("username:", a), await s({
|
|
22
|
+
platform: t,
|
|
23
|
+
username: a,
|
|
24
|
+
projectName: e
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
export {
|
|
28
|
-
|
|
28
|
+
G as cloneDoneCodingSeries
|
|
29
29
|
};
|
package/es/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { o as t, C as l, G as d, I as c, S as C, m as p, l as f, f as h, h as u, c as k, b as I, n as E, k as b, j as H, e as g, d as y } from "./index-
|
|
3
|
-
import { a as T } from "./index-
|
|
2
|
+
import { o as t, C as l, G as d, I as c, S as C, m as p, l as f, f as h, h as u, c as k, b as I, n as E, k as b, j as H, e as g, d as y } from "./index-8640f971.js";
|
|
3
|
+
import { a as T } from "./index-166c6260.js";
|
|
4
4
|
import "@done-coding/cli-utils";
|
|
5
5
|
import "node:child_process";
|
|
6
6
|
import "node:fs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-git",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12",
|
|
4
4
|
"description": "git跨平台操作命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"sideEffects": false,
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@done-coding/cli-inject": "0.5.
|
|
55
|
+
"@done-coding/cli-inject": "0.5.20",
|
|
56
56
|
"@types/node": "^18.0.0",
|
|
57
57
|
"@types/yargs": "^17.0.28",
|
|
58
58
|
"rimraf": "^6.0.1",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"node": ">=18.0.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@done-coding/cli-utils": "0.
|
|
67
|
+
"@done-coding/cli-utils": "0.8.1",
|
|
68
68
|
"@done-coding/request-axios": "^1.2.2",
|
|
69
69
|
"axios": "^1.8.4"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "0930f800167c04a86b56eae9741872dd51bec0c6"
|
|
72
72
|
}
|