diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index a97639795..51a6bc553 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -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 + } } } diff --git a/pkg/integration/tests/commit/commit_with_non_matching_branch_name.go b/pkg/integration/tests/commit/commit_with_non_matching_branch_name.go index 490bbf9f8..1075c7bb1 100644 --- a/pkg/integration/tests/commit/commit_with_non_matching_branch_name.go +++ b/pkg/integration/tests/commit/commit_with_non_matching_branch_name.go @@ -30,9 +30,6 @@ var CommitWithNonMatchingBranchName = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().CommitMessagePanel(). Title(Equals("Commit summary")). - /* EXPECTED: InitialText(Equals("")) - ACTUAL: */ - InitialText(Equals("branchnomatch")) }, })