Skip to content

Commit 7b46462

Browse files
committed
Make the master branch name cofigurable
1 parent 80f85b7 commit 7b46462

File tree

7 files changed

+44
-3
lines changed

7 files changed

+44
-3
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ npm i -g @xniva/git-shortcuts
3131
| `glp` | `git show-branch --no-name HEAD` | Print the last commit message |
3232
| `glc` | `git show-branch --no-name HEAD` | Copy and Print the last commit message |
3333
| `gsf` | `gcm && gpm && git merge --no-commit --no-ff origin/${featureBranch}` | List the changes of a feature branch w.r.t master - for review |
34+
35+
### Master branch name is configurable:
36+
37+
Add a .env file in the directory where you are using the shortcuts and add the following line to set the master branch name
38+
39+
```
40+
MASTER_BRANCH_NAME=main // or any other branch name
41+
```

lib/git_checkout_master/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import runCommand from "./../utils/run_command.js";
2+
import getMasterBranchName from "../utils/get_master_branch_name.js";
23

34
const main = () => {
4-
runCommand("git checkout master");
5+
const branchName = getMasterBranchName();
6+
runCommand(`git checkout ${branchName}`);
57
};
68

79
export default main;

lib/git_merge_master/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import getMasterBranchName from "../utils/get_master_branch_name.js";
12
import runCommand from "./../utils/run_command.js";
23

34
const main = () => {
4-
runCommand("git merge origin master");
5+
const branchName = getMasterBranchName();
6+
runCommand(`git merge origin ${branchName}`);
57
};
68

79
export default main;

lib/git_pull_master/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import getMasterBranchName from "../utils/get_master_branch_name.js";
12
import runCommand from "./../utils/run_command.js";
23

34
const main = () => {
4-
runCommand("git pull origin master");
5+
const branchName = getMasterBranchName();
6+
runCommand(`git pull origin ${branchName}`);
57
};
68

79
export default main;

lib/utils/get_master_branch_name.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from "fs";
2+
import dotenv from "dotenv";
3+
4+
const getMasterBranchName = () => {
5+
let branchName = "master";
6+
if (fs.existsSync("./.env")) {
7+
dotenv.config();
8+
branchName = process.env.MASTER_BRANCH_NAME || branchName;
9+
}
10+
return branchName;
11+
};
12+
13+
export default getMasterBranchName;

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"test": "echo \"Error: no test specified\" && exit 1"
2727
},
2828
"dependencies": {
29+
"dotenv": "16.4.5",
2930
"inquirer": "^9.1.4"
3031
}
3132
}

0 commit comments

Comments
 (0)