Skip to content

Commit 81e24f1

Browse files
committed
feat: 新增 log 命令
1 parent 740a6b5 commit 81e24f1

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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)