Skip to content

Commit 223ed14

Browse files
authored
Merge pull request #16 from xnivaxhzne/feature-git-commit
Add code for git commit message
2 parents 2d72efe + 06bfa91 commit 223ed14

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ npm i -g @xniva/git-shortcuts
3434
| `gma` | `git merge --abort` | Abort the merge |
3535
| `grb` | `git reset --${hardOrSoft} origin/$(git rev-parse --abbrev-ref HEAD)` | Reset the current branch to its remote equivalent |
3636
| `gphf` | `git push origin HEAD --force` | Force push the current branch |
37+
| `gc` | `git commit -m ${commitMessage}` | Commit with the give message |
3738

3839
### Master branch name is configurable:
3940

bin/git_commit_message.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /usr/bin/env node
2+
import main from "../lib/git_commit_message/index.js";
3+
4+
main();

lib/git_commit_message/index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import runCommand from "../utils/run_command.js";
2+
import inquirer from "inquirer";
3+
4+
const getCommitMessage = async () => {
5+
const inputFields = [
6+
{
7+
type: "input",
8+
name: "message",
9+
message: "Enter the commit message: ",
10+
},
11+
];
12+
13+
const { message } = await inquirer.prompt(inputFields);
14+
return message;
15+
};
16+
17+
const main = async () => {
18+
let commitMessage = process.argv.slice(2).join(" ");
19+
20+
if (!commitMessage) {
21+
commitMessage = await getCommitMessage();
22+
}
23+
24+
console.log(commitMessage);
25+
26+
runCommand(`git commit -m "${commitMessage}"`);
27+
};
28+
29+
export default main;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"gsf": "bin/git_see_feature_files.js",
2121
"gma": "bin/git_merge_abort.js",
2222
"grb": "bin/git_reset_current_branch.js",
23-
"gphf": "bin/git_push_head_force.js"
23+
"gphf": "bin/git_push_head_force.js",
24+
"gc": "bin/git_commit_message.js"
2425
},
2526
"author": "Kavinkumar R",
2627
"license": "MIT",

0 commit comments

Comments
 (0)