Skip to content

Commit 25dd262

Browse files
authored
Merge pull request #5 from lxfu1/log-command
Log command
2 parents 740a6b5 + 0c4c875 commit 25dd262

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
## 更新日志
22

3+
### 1.0.4
4+
5+
- feat: 新增 `lg` 命令
6+
7+
- fix: 修复 `p``pr` 命令
8+
39
### 1.0.3
410

511
- fix: 修复 `r` 命令
612

713
### 1.0.2
814

9-
- `l` 命令变更为 `b`
15+
- `l` 命令变更为 `b`
1016

1117
### 1.0.1
1218

1319
新增 `a cm r p pr pl co cb` 命令
1420

1521
### 1.0.0
1622

17-
发布正式版本
23+
发布正式版本

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ $ npm i -g @lxfu/gm
2222
- `gm cm commitInfo` : 相当于 `git commit -m commitInfo`
2323
- `gm r commitId` : 相当于 `git reset commitId`
2424
- `gm p` : 相当于 `git push`
25+
- `gm p -f`: 相当于 `git push -f`
2526
- `gm pr` : 用于没有远程分支的提交
26-
- `gm pr` : 相当于 `git push origin HEAD`
27-
- `gm pr branch` : 相当于 `git push --set-upstream origin branch`
27+
- `gm pr [-f]` : 相当于 `git push origin HEAD`
28+
- `gm pr branch [-f]` : 相当于 `git push --set-upstream origin branch`
2829
- `gm pl` : 相当于 `git pull`
2930
- `gm co branch` : 相当于 `git checkout branch`
3031
- `gm cb branch` : 相当于 `git checkout -b branch`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lxfu/gm",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Git branch manger",
55
"bin": "./bin/index.js",
66
"scripts": {},

src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
onPushRemote,
1313
onPull,
1414
onCheckoutB,
15+
onLog,
1516
} = require("./module");
1617

1718
const program = new commander.Command("gm");
@@ -42,10 +43,15 @@ program
4243

4344
program.command("r <commit-id>").description("Git reset").action(onReset);
4445

45-
program.command("p").description("Git push").action(onPush);
46+
program
47+
.command("p")
48+
.description("Git push")
49+
.option("-f", "force push")
50+
.action(onPush);
4651
program
4752
.command("pr [branch]")
4853
.description("Git push origin")
54+
.option("-f", "force push")
4955
.action(onPushRemote);
5056
program.command("pl").description("Git pull").action(onPull);
5157

@@ -55,4 +61,9 @@ program
5561
.description("Git checkout -b")
5662
.action(onCheckoutB);
5763

64+
program
65+
.command("lg [depth]")
66+
.description("Git log oneline -depth")
67+
.action(onLog);
68+
5869
program.parse(process.argv);

src/module.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ const onCheckoutB = (branch) => {
7474
exit(1);
7575
};
7676

77-
const onPush = () => {
78-
exec(`git push`);
77+
const onPush = (option) => {
78+
const { f } = option;
79+
exec(`git push ${f ? "-f" : ""}`);
7980
exit(1);
8081
};
8182

@@ -84,11 +85,12 @@ const onPull = () => {
8485
exit(1);
8586
};
8687

87-
const onPushRemote = (branch) => {
88+
const onPushRemote = (branch, option) => {
89+
const { f } = option;
8890
if (branch) {
89-
exec(`git push --set-upstream origin ${branch}`);
91+
exec(`git push --set-upstream origin ${branch} ${f ? "-f" : ""}`);
9092
} else {
91-
exec(`git push origin HEAD`);
93+
exec(`git push origin HEAD ${f ? "-f" : ""}`);
9294
}
9395
exit(1);
9496
};
@@ -98,6 +100,11 @@ const onReset = (commitId) => {
98100
exit(1);
99101
};
100102

103+
const onLog = (depth = 50) => {
104+
exec(`git log --oneline -${depth}`);
105+
exit(1);
106+
};
107+
101108
module.exports = {
102109
onList,
103110
onDelete,
@@ -110,4 +117,5 @@ module.exports = {
110117
onPushRemote,
111118
onPull,
112119
onCheckoutB,
120+
onLog,
113121
};

0 commit comments

Comments
 (0)