diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3e9c5..ed0a888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,18 @@ ## 更新日志 +### 1.0.4 + +- feat: 新增 `lg` 命令 + +- fix: 修复 `p`、`pr` 命令 + ### 1.0.3 - fix: 修复 `r` 命令 ### 1.0.2 -- `l` 命令变更为 `b` +- `l` 命令变更为 `b` ### 1.0.1 @@ -14,4 +20,4 @@ ### 1.0.0 -发布正式版本 \ No newline at end of file +发布正式版本 diff --git a/README.md b/README.md index 2031870..877adfe 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,10 @@ $ npm i -g @lxfu/gm - `gm cm commitInfo` : 相当于 `git commit -m commitInfo` - `gm r commitId` : 相当于 `git reset commitId` - `gm p` : 相当于 `git push` + - `gm p -f`: 相当于 `git push -f` - `gm pr` : 用于没有远程分支的提交 - - `gm pr` : 相当于 `git push origin HEAD` - - `gm pr branch` : 相当于 `git push --set-upstream origin branch` + - `gm pr [-f]` : 相当于 `git push origin HEAD` + - `gm pr branch [-f]` : 相当于 `git push --set-upstream origin branch` - `gm pl` : 相当于 `git pull` - `gm co branch` : 相当于 `git checkout branch` - `gm cb branch` : 相当于 `git checkout -b branch` diff --git a/package.json b/package.json index 742d26a..a4fd200 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lxfu/gm", - "version": "1.0.3", + "version": "1.0.4", "description": "Git branch manger", "bin": "./bin/index.js", "scripts": {}, diff --git a/src/index.js b/src/index.js index 4efdabf..af1ea87 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,7 @@ const { onPushRemote, onPull, onCheckoutB, + onLog, } = require("./module"); const program = new commander.Command("gm"); @@ -42,10 +43,15 @@ program program.command("r ").description("Git reset").action(onReset); -program.command("p").description("Git push").action(onPush); +program + .command("p") + .description("Git push") + .option("-f", "force push") + .action(onPush); program .command("pr [branch]") .description("Git push origin") + .option("-f", "force push") .action(onPushRemote); program.command("pl").description("Git pull").action(onPull); @@ -55,4 +61,9 @@ program .description("Git checkout -b") .action(onCheckoutB); +program + .command("lg [depth]") + .description("Git log oneline -depth") + .action(onLog); + program.parse(process.argv); diff --git a/src/module.js b/src/module.js index 41502c1..1164cca 100644 --- a/src/module.js +++ b/src/module.js @@ -74,8 +74,9 @@ const onCheckoutB = (branch) => { exit(1); }; -const onPush = () => { - exec(`git push`); +const onPush = (option) => { + const { f } = option; + exec(`git push ${f ? "-f" : ""}`); exit(1); }; @@ -84,11 +85,12 @@ const onPull = () => { exit(1); }; -const onPushRemote = (branch) => { +const onPushRemote = (branch, option) => { + const { f } = option; if (branch) { - exec(`git push --set-upstream origin ${branch}`); + exec(`git push --set-upstream origin ${branch} ${f ? "-f" : ""}`); } else { - exec(`git push origin HEAD`); + exec(`git push origin HEAD ${f ? "-f" : ""}`); } exit(1); }; @@ -98,6 +100,11 @@ const onReset = (commitId) => { exit(1); }; +const onLog = (depth = 50) => { + exec(`git log --oneline -${depth}`); + exit(1); +}; + module.exports = { onList, onDelete, @@ -110,4 +117,5 @@ module.exports = { onPushRemote, onPull, onCheckoutB, + onLog, };