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 {
prefixPattern := commitPrefixConfig.Pattern
prefixReplace := commitPrefixConfig.Replace
branchName := self.refHelper.GetCheckedOutRef().Name
rgx, err := regexp.Compile(prefixPattern)
if err != nil {
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
}
}
}