-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple commit prefixes #4253
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,22 @@ func loadUserConfig(configFiles []*ConfigFile, base *UserConfig) (*UserConfig, e | |
return base, nil | ||
} | ||
|
||
func (a *CommitPrefixConfigs) UnmarshalYAML(value *yaml.Node) error { | ||
var multi []CommitPrefixConfig | ||
err := value.Decode(&multi) | ||
if err != nil { | ||
var single CommitPrefixConfig | ||
err := value.Decode(&single) | ||
if err != nil { | ||
return err | ||
} | ||
*a = []CommitPrefixConfig{single} | ||
} else { | ||
*a = multi | ||
} | ||
return nil | ||
} | ||
Comment on lines
+215
to
+229
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that go-yaml has no way to express this behavior, so I created a newtype and put the behavior on it. Taken from the comments of go-yaml/yaml#100 |
||
|
||
// Do any backward-compatibility migrations of things that have changed in the | ||
// config over time; examples are renaming a key to a better name, moving a key | ||
// from one container to another, or changing the type of a key (e.g. from bool | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,9 +256,9 @@ type GitConfig struct { | |
// If true, do not allow force pushes | ||
DisableForcePushing bool `yaml:"disableForcePushing"` | ||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix | ||
CommitPrefix *CommitPrefixConfig `yaml:"commitPrefix"` | ||
CommitPrefix CommitPrefixConfigs `yaml:"commitPrefix"` | ||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix | ||
CommitPrefixes map[string]CommitPrefixConfig `yaml:"commitPrefixes"` | ||
CommitPrefixes map[string]CommitPrefixConfigs `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 🚀 | ||
|
@@ -271,6 +271,8 @@ type GitConfig struct { | |
TruncateCopiedCommitHashesTo int `yaml:"truncateCopiedCommitHashesTo"` | ||
} | ||
|
||
type CommitPrefixConfigs []CommitPrefixConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newtype just for yaml deserialization purposes to maintain backwards compatibility. |
||
|
||
type PagerType string | ||
|
||
func (PagerType) JSONSchemaExtend(schema *jsonschema.Schema) { | ||
|
@@ -784,7 +786,7 @@ func GetDefaultConfig() *UserConfig { | |
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --", | ||
AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium", | ||
DisableForcePushing: false, | ||
CommitPrefixes: map[string]CommitPrefixConfig(nil), | ||
CommitPrefixes: map[string]CommitPrefixConfigs(nil), | ||
BranchPrefix: "", | ||
ParseEmoji: false, | ||
TruncateCopiedCommitHashesTo: 12, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package commit | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var CommitWithFallthroughPrefix = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Commit with defined config commitPrefix", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(cfg *config.AppConfig) { | ||
cfg.GetUserConfig().Git.CommitPrefix = config.CommitPrefixConfigs{ | ||
{Pattern: "^doesntmatch-(\\w+).*", Replace: "[BAD $1]: "}, | ||
{Pattern: "^\\w+\\/(\\w+-\\w+).*", Replace: "[GOOD $1]: "}, | ||
} | ||
cfg.GetUserConfig().Git.CommitPrefixes = map[string]config.CommitPrefixConfigs{ | ||
"DifferentProject": {{Pattern: "^otherthatdoesn'tmatch-(\\w+).*", Replace: "[BAD $1]: "}}, | ||
} | ||
}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.NewBranch("feature/TEST-001") | ||
shell.CreateFile("test-commit-prefix", "This is foo bar") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Commits(). | ||
IsEmpty() | ||
|
||
t.Views().Files(). | ||
IsFocused(). | ||
PressPrimaryAction(). | ||
Press(keys.Files.CommitChanges) | ||
|
||
t.ExpectPopup().CommitMessagePanel(). | ||
Title(Equals("Commit summary")). | ||
InitialText(Equals("[GOOD TEST-001]: ")). | ||
Type("my commit message"). | ||
Cancel() | ||
|
||
t.Views().Files(). | ||
IsFocused(). | ||
Press(keys.Files.CommitChanges) | ||
|
||
t.ExpectPopup().CommitMessagePanel(). | ||
Title(Equals("Commit summary")). | ||
InitialText(Equals("[GOOD TEST-001]: my commit message")). | ||
Type(". Added something else"). | ||
Confirm() | ||
|
||
t.Views().Commits().Focus() | ||
t.Views().Main().Content(Contains("[GOOD TEST-001]: my commit message. Added something else")) | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was automatically removed by
go generate
. I guess since the element is now a sequence instead of a mapping. Is there some way we can tag the field in the config struct definition so that these details continue to show here?