1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Ensure branch name matches pattern before replace

Amend test for non-matching branch name
This commit is contained in:
Luke Swan
2024-06-30 01:07:15 +00:00
committed by Stefan Haller
parent 07fe828f60
commit 968060a5ec
2 changed files with 6 additions and 5 deletions

View File

@ -152,12 +152,16 @@ func (self *WorkingTreeHelper) HandleCommitPress() error {
if commitPrefixConfig != nil { if commitPrefixConfig != nil {
prefixPattern := commitPrefixConfig.Pattern prefixPattern := commitPrefixConfig.Pattern
prefixReplace := commitPrefixConfig.Replace prefixReplace := commitPrefixConfig.Replace
branchName := self.refHelper.GetCheckedOutRef().Name
rgx, err := regexp.Compile(prefixPattern) rgx, err := regexp.Compile(prefixPattern)
if err != nil { if err != nil {
return fmt.Errorf("%s: %s", self.c.Tr.CommitPrefixPatternError, err.Error()) return fmt.Errorf("%s: %s", self.c.Tr.CommitPrefixPatternError, err.Error())
} }
prefix := rgx.ReplaceAllString(self.refHelper.GetCheckedOutRef().Name, prefixReplace)
message = prefix if rgx.MatchString(branchName) {
prefix := rgx.ReplaceAllString(branchName, prefixReplace)
message = prefix
}
} }
} }

View File

@ -30,9 +30,6 @@ var CommitWithNonMatchingBranchName = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectPopup().CommitMessagePanel(). t.ExpectPopup().CommitMessagePanel().
Title(Equals("Commit summary")). Title(Equals("Commit summary")).
/* EXPECTED:
InitialText(Equals("")) InitialText(Equals(""))
ACTUAL: */
InitialText(Equals("branchnomatch"))
}, },
}) })