From 968060a5ec13a7804301a1368899b756bcfb04b3 Mon Sep 17 00:00:00 2001 From: Luke Swan Date: Sun, 30 Jun 2024 01:07:15 +0000 Subject: [PATCH] Ensure branch name matches pattern before replace Amend test for non-matching branch name --- pkg/gui/controllers/helpers/working_tree_helper.go | 8 ++++++-- .../tests/commit/commit_with_non_matching_branch_name.go | 3 --- 2 files changed, 6 insertions(+), 5 deletions(-) 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")) }, })