summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliot Cubit <elliot@censys.com>2024-04-09 15:41:26 -0400
committerJesse Duffield <jessedduffield@gmail.com>2024-07-06 21:06:28 +1000
commit5959f7bc8ef76d2a79e6c46ecd7039529337f2fc (patch)
tree3e5e4645ca74dc39e20cda40da44d1554d1decb0
parent436240bbeb44bdcea9ca61dcaed807a59ed7892f (diff)
Allow setting a default name when creating new branches
-rw-r--r--docs/Config.md18
-rw-r--r--pkg/config/user_config.go3
-rw-r--r--pkg/gui/controllers/helpers/refs_helper.go4
-rw-r--r--pkg/integration/tests/commit/new_branch_with_prefix.go33
-rw-r--r--pkg/integration/tests/test_list.go1
-rw-r--r--schema/config.json4
6 files changed, 63 insertions, 0 deletions
diff --git a/docs/Config.md b/docs/Config.md
index 358e7be5b..8506f7aed 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -323,6 +323,9 @@ git:
# Replace directive. E.g. for 'feature/AB-123' to start the commit message with 'AB-123 ' use "[$1] "
replace: ""
+ # See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-branch-name-prefix
+ branchPrefix: ""
+
# If true, parse emoji strings in commit messages e.g. render :rocket: as 🚀
# (This should really be under 'gui', not 'git')
parseEmoji: false
@@ -885,6 +888,21 @@ git:
replace: '[$1] '
```
+## Predefined branch name prefix
+
+In situations where certain naming pattern is used for branches, this can be used to populate new branch creation with a static prefix.
+
+Example:
+
+Some branches:
+- jsmith/AB-123
+- cwilson/AB-125
+
+```yaml
+git:
+ branchPrefix: "firstlast/"
+```
+
## Custom git log command
You can override the `git log` command that's used to render the log of the selected branch like so:
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go
index b5bccba45..c0613865e 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -236,6 +236,8 @@ type GitConfig struct {
CommitPrefix *CommitPrefixConfig `yaml:"commitPrefix"`
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix
CommitPrefixes map[string]CommitPrefixConfig `yaml:"commitPrefixes"`
+ // See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-branch-name-prefix
+ BranchPrefix string `yaml:"branchPrefix"`
// If true, parse emoji strings in commit messages e.g. render :rocket: as 🚀
// (This should really be under 'gui', not 'git')
ParseEmoji bool `yaml:"parseEmoji"`
@@ -750,6 +752,7 @@ func GetDefaultConfig() *UserConfig {
AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium",
DisableForcePushing: false,
CommitPrefixes: map[string]CommitPrefixConfig(nil),
+ BranchPrefix: "",
ParseEmoji: false,
TruncateCopiedCommitHashesTo: 12,
},
diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go
index 095e9848b..f471f57e2 100644
--- a/pkg/gui/controllers/helpers/refs_helper.go
+++ b/pkg/gui/controllers/helpers/refs_helper.go
@@ -274,6 +274,10 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
},
)
+ if suggestedBranchName == "" {
+ suggestedBranchName = self.c.UserConfig.Git.BranchPrefix
+ }
+
return self.c.Prompt(types.PromptOpts{
Title: message,
InitialContent: suggestedBranchName,
diff --git a/pkg/integration/tests/commit/new_branch_with_prefix.go b/pkg/integration/tests/commit/new_branch_with_prefix.go
new file mode 100644
index 000000000..21381630e
--- /dev/null
+++ b/pkg/integration/tests/commit/new_branch_with_prefix.go
@@ -0,0 +1,33 @@
+package commit
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var NewBranchWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Creating a new branch from a commit with a default name",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(cfg *config.AppConfig) {
+ cfg.UserConfig.Git.BranchPrefix = "myprefix/"
+ },
+ SetupRepo: func(shell *Shell) {
+ shell.
+ EmptyCommit("commit 1")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains("commit 1").IsSelected(),
+ ).
+ SelectNextItem().
+ Press(keys.Universal.New).
+ Tap(func() {
+ branchName := "my-branch-name"
+ t.ExpectPopup().Prompt().Title(Contains("New branch name")).Type(branchName).Confirm()
+ t.Git().CurrentBranchName("myprefix/" + branchName)
+ })
+ },
+})
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index ee547e950..cbd3471e5 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -92,6 +92,7 @@ var tests = []*components.IntegrationTest{
commit.History,
commit.HistoryComplex,
commit.NewBranch,
+ commit.NewBranchWithPrefix,
commit.PasteCommitMessage,
commit.PasteCommitMessageOverExisting,
commit.PreserveCommitMessage,
diff --git a/schema/config.json b/schema/config.json
index 580765c0f..cf67f78c8 100644
--- a/schema/config.json
+++ b/schema/config.json
@@ -638,6 +638,10 @@
"type": "object",
"description": "See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix"
},
+ "branchPrefix": {
+ "type": "string",
+ "description": "See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-branch-name-prefix"
+ },
"parseEmoji": {
"type": "boolean",
"description": "If true, parse emoji strings in commit messages e.g. render :rocket: as 🚀\n(This should really be under 'gui', not 'git')",