forked from jesseduffield/lazygit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support multiple commit prefixes
This implementation, unlike that proposed in jesseduffield#4253 keeps the yaml schema easy, and does a migration from the single elements to a sequence of elements.
- Loading branch information
Showing
14 changed files
with
395 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func TestCommitPrefixMigrations(t *testing.T) { | ||
scenarios := []struct { | ||
name string | ||
input string | ||
expected string | ||
}{ | ||
{ | ||
"Empty String", | ||
"", | ||
"", | ||
}, { | ||
"Single CommitPrefix Rename", | ||
` | ||
git: | ||
commitPrefix: | ||
pattern: "^\\w+-\\w+.*" | ||
replace: '[JIRA $0] '`, | ||
` | ||
git: | ||
commitPrefix: | ||
- pattern: "^\\w+-\\w+.*" | ||
replace: '[JIRA $0] '`, | ||
}, { | ||
"Complicated CommitPrefixes Rename", | ||
` | ||
git: | ||
commitPrefixes: | ||
foo: | ||
pattern: "^\\w+-\\w+.*" | ||
replace: '[OTHER $0] ' | ||
CrazyName!@#$^*&)_-)[[}{f{[]: | ||
pattern: "^foo.bar*" | ||
replace: '[FUN $0] '`, | ||
` | ||
git: | ||
commitPrefixes: | ||
foo: | ||
- pattern: "^\\w+-\\w+.*" | ||
replace: '[OTHER $0] ' | ||
CrazyName!@#$^*&)_-)[[}{f{[]: | ||
- pattern: "^foo.bar*" | ||
replace: '[FUN $0] '`, | ||
}, { | ||
"Incomplete Configuration", | ||
"git:", | ||
"git:", | ||
}, | ||
} | ||
|
||
for _, s := range scenarios { | ||
t.Run(s.name, func(t *testing.T) { | ||
expectedConfig := GetDefaultConfig() | ||
err := yaml.Unmarshal([]byte(s.expected), expectedConfig) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
actual, err := computeMigratedConfig("path doesn't matter", []byte(s.input)) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
actualConfig := GetDefaultConfig() | ||
err = yaml.Unmarshal(actual, actualConfig) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
assert.Equal(t, expectedConfig, actualConfig) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
pkg/integration/tests/commit/commit_with_fallthrough_prefix.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 multiple CommitPrefixConfig", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(cfg *config.AppConfig) { | ||
cfg.GetUserConfig().Git.CommitPrefix = []config.CommitPrefixConfig{ | ||
{Pattern: "^doesntmatch-(\\w+).*", Replace: "[BAD $1]: "}, | ||
{Pattern: "^\\w+\\/(\\w+-\\w+).*", Replace: "[GOOD $1]: "}, | ||
} | ||
cfg.GetUserConfig().Git.CommitPrefixes = map[string][]config.CommitPrefixConfig{ | ||
"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")) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.