From ced70903ecf5e528bbcdb73adf4ef182bdc7b285 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 3 Apr 2025 15:04:52 +0200 Subject: [PATCH] Prefill the commit subject with the skipHook prefix when pressing `w` We removed prefilling the skipHook prefix in b102646b207 with the intention of making it clearer that using the prefix in normal commits and typing `w` to skip hooks are now two independent features. It turns out that some people liked it with prefilling the prefix and perceive it as a regression, so put it back in. But only if we don't have a preserved message; this is an important use case, when you try to make a normal commit, the hook fails, and then you want to make the same commit with skipping the hook, but with the same message that you already typed. --- pkg/gui/controllers/helpers/working_tree_helper.go | 8 +++++++- pkg/integration/tests/commit/commit_wip_with_prefix.go | 9 +++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index 482c31c0d..b5ea1b6bd 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -139,7 +139,13 @@ func (self *WorkingTreeHelper) HandleCommitEditorPress() error { } func (self *WorkingTreeHelper) HandleWIPCommitPress() error { - return self.HandleCommitPressWithMessage("", true) + var initialMessage string + preservedMessage := self.c.Contexts().CommitMessage.GetPreservedMessageAndLogError() + if preservedMessage == "" { + // Use the skipHook prefix only if we don't have a preserved message + initialMessage = self.c.UserConfig().Git.SkipHookPrefix + } + return self.HandleCommitPressWithMessage(initialMessage, true) } func (self *WorkingTreeHelper) HandleCommitPress() error { diff --git a/pkg/integration/tests/commit/commit_wip_with_prefix.go b/pkg/integration/tests/commit/commit_wip_with_prefix.go index 822a2b6ef..52ca52c23 100644 --- a/pkg/integration/tests/commit/commit_wip_with_prefix.go +++ b/pkg/integration/tests/commit/commit_wip_with_prefix.go @@ -32,7 +32,8 @@ var CommitWipWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().CommitMessagePanel(). Title(Equals("Commit summary")). - Type("foo"). + InitialText(Equals("WIP")). + Type(" foo"). Cancel() t.Views().Files(). @@ -41,7 +42,7 @@ var CommitWipWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().CommitMessagePanel(). Title(Equals("Commit summary")). - InitialText(Equals("foo")). + InitialText(Equals("WIP foo")). Type(" bar"). Cancel() @@ -51,11 +52,11 @@ var CommitWipWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().CommitMessagePanel(). Title(Equals("Commit summary")). - InitialText(Equals("foo bar")). + InitialText(Equals("WIP foo bar")). Type(". Added something else"). Confirm() t.Views().Commits().Focus() - t.Views().Main().Content(Contains("foo bar. Added something else")) + t.Views().Main().Content(Contains("WIP foo bar. Added something else")) }, })