Skip to content

Commit de67878

Browse files
committed
SelectCommitRanges: branch prefix via env + cli arg
1 parent 5fc4ff0 commit de67878

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ To update your local branch with the latest changes in the remote branch (e.g. `
8383
git stack rebase
8484
```
8585

86+
### Customizing branch name
87+
88+
By default `git stack` generates a unique branch name such as `gs-3cmrMBSUj`.
89+
90+
You can specify a prefix for the generated branch name by using either the environment variable or the command line option.
91+
In the example below branches would be generated such as `dev/magus/gs-3cmrMBSUj`.
92+
93+
```bash
94+
GIT_STACK_BRANCH_PREFIX="dev/magus/" git stack
95+
96+
git stack --branch-prefix="dev/magus/"
97+
```
98+
8699
## Why?
87100

88101
The goal of `git stack` is to combine the **simplicity of developing in a single branch** in order to **preserve your commit history** while also **grouping commits into pull requests for code review**.

src/app/SelectCommitRanges.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,21 @@ function SelectCommitRangesInternal(props: Props) {
387387
</Ink.Box>
388388
);
389389

390+
function get_group_id() {
391+
let branch_prefix = "";
392+
393+
// branch prefix via cli flag or env var
394+
// cli flag takes precedence since it is more explicit
395+
if (argv["branch-prefix"]) {
396+
branch_prefix = argv["branch-prefix"];
397+
} else if (process.env.GIT_STACK_BRANCH_PREFIX) {
398+
branch_prefix = process.env.GIT_STACK_BRANCH_PREFIX;
399+
}
400+
401+
return `${branch_prefix}${gs_short_id()}`;
402+
}
390403
function submit_group_input(title: string) {
391-
const id = gs_short_id();
404+
const id = get_group_id();
392405

393406
actions.output(
394407
<FormatText

src/command.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ const DefaultOptions = {
111111
description: "Open all PRs as drafts",
112112
},
113113

114+
"branch-prefix": {
115+
type: "string",
116+
default: "",
117+
description: "Prefix for generated branch names, e.g. dev/magus/",
118+
},
119+
114120
"template": {
115121
type: "boolean",
116122
default: true,

src/types/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ declare namespace NodeJS {
55
CLI_VERSION?: string;
66
GIT_STACK_STANDALONE?: "true" | "false";
77
GIT_SEQUENCE_EDITOR_SCRIPT?: string;
8+
GIT_STACK_BRANCH_PREFIX?: string;
89
}
910
}

0 commit comments

Comments
 (0)