Skip to content

Commit

Permalink
Merge pull request #5 from lxfu1/log-command
Browse files Browse the repository at this point in the history
Log command
  • Loading branch information
lxfu1 authored May 13, 2022
2 parents 740a6b5 + 0c4c875 commit 25dd262
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
## 更新日志

### 1.0.4

- feat: 新增 `lg` 命令

- fix: 修复 `p``pr` 命令

### 1.0.3

- fix: 修复 `r` 命令

### 1.0.2

- `l` 命令变更为 `b`
- `l` 命令变更为 `b`

### 1.0.1

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

### 1.0.0

发布正式版本
发布正式版本
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lxfu/gm",
"version": "1.0.3",
"version": "1.0.4",
"description": "Git branch manger",
"bin": "./bin/index.js",
"scripts": {},
Expand Down
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
onPushRemote,
onPull,
onCheckoutB,
onLog,
} = require("./module");

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

program.command("r <commit-id>").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);

Expand All @@ -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);
18 changes: 13 additions & 5 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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);
};
Expand All @@ -98,6 +100,11 @@ const onReset = (commitId) => {
exit(1);
};

const onLog = (depth = 50) => {
exec(`git log --oneline -${depth}`);
exit(1);
};

module.exports = {
onList,
onDelete,
Expand All @@ -110,4 +117,5 @@ module.exports = {
onPushRemote,
onPull,
onCheckoutB,
onLog,
};

0 comments on commit 25dd262

Please sign in to comment.