Skip to content

Commit 7329fcd

Browse files
authored
Merge pull request #19 from xnivaxhzne/feature-gca
Commit all the files with the give message
2 parents a609cd3 + 26fb51b commit 7329fcd

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ 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 |
37+
| `gc` | `git commit -m ${commitMessage}` | Commit the staged files with the give message |
3838
| `gcpm` | `gcm && gpm` | Checkout master and pull |
39+
| `gca` | `git commit -am ${commitMessage}` | Commit all the files with the give message |
3940

4041
### Master branch name is configurable:
4142

bin/git_add_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_add_commit_message/index.js";
3+
4+
main();

lib/git_add_commit_message/index.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
runCommand(`git add . && git commit -m "${commitMessage}"`);
25+
};
26+
27+
export default main;

lib/git_commit_message/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const main = async () => {
2121
commitMessage = await getCommitMessage();
2222
}
2323

24-
console.log(commitMessage);
25-
2624
runCommand(`git commit -m "${commitMessage}"`);
2725
};
2826

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"grb": "bin/git_reset_current_branch.js",
2323
"gphf": "bin/git_push_head_force.js",
2424
"gc": "bin/git_commit_message.js",
25+
"gca": "bin/git_add_commit_message.js",
2526
"gcpm": "bin/git_checkout_pull_master.js"
2627
},
2728
"author": "Kavinkumar R",

0 commit comments

Comments
 (0)