From 2a7ce19b73676d99d27ac9291ecabd1dbb84f94a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 2 Jul 2025 10:54:51 +0200 Subject: [PATCH] Use a better name for the auto-stash for creating a new branch For the case of creating a new branch by moving commits to it, we were using the current (old) branch name in the stash name; change this to use the new name instead. --- pkg/gui/controllers/helpers/refs_helper.go | 18 +++++++++--------- pkg/i18n/english.go | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index d7ac0845f..993ffb423 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -355,7 +355,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest Title: self.c.Tr.AutoStashTitle, Prompt: self.c.Tr.AutoStashPrompt, HandleConfirm: func() error { - if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + newBranchName); err != nil { + if err := self.c.Git().Stash.Push(fmt.Sprintf(self.c.Tr.AutoStashForNewBranch, newBranchName)); err != nil { return err } if err := newBranchFunc(newBranchName, from); err != nil { @@ -389,7 +389,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error { return err } - withNewBranchNamePrompt := func(baseBranchName string, f func(string, string) error) error { + withNewBranchNamePrompt := func(baseBranchName string, f func(string) error) error { prompt := utils.ResolvePlaceholderString( self.c.Tr.NewBranchNameBranchOff, map[string]string{ @@ -408,7 +408,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error { self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch) newBranchName := SanitizedBranchName(response) return self.c.WithWaitingStatus(self.c.Tr.MovingCommitsToNewBranchStatus, func(gocui.Task) error { - return f(currentBranch.Name, newBranchName) + return f(newBranchName) }) }, }) @@ -447,8 +447,8 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error { { Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchFromBaseItem, shortBaseBranchName), OnPress: func() error { - return withNewBranchNamePrompt(shortBaseBranchName, func(currentBranch string, newBranchName string) error { - return self.moveCommitsToNewBranchOffOfMainBranch(currentBranch, newBranchName, baseBranchRef) + return withNewBranchNamePrompt(shortBaseBranchName, func(newBranchName string) error { + return self.moveCommitsToNewBranchOffOfMainBranch(newBranchName, baseBranchRef) }) }, }, @@ -462,14 +462,14 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error { }) } -func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(currentBranch string, newBranchName string) error { +func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(newBranchName string) error { if err := self.c.Git().Branch.NewWithoutCheckout(newBranchName, "HEAD"); err != nil { return err } mustStash := IsWorkingTreeDirty(self.c.Model().Files) if mustStash { - if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + currentBranch); err != nil { + if err := self.c.Git().Stash.Push(fmt.Sprintf(self.c.Tr.AutoStashForNewBranch, newBranchName)); err != nil { return err } } @@ -495,14 +495,14 @@ func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(currentBran return nil } -func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(currentBranch string, newBranchName string, baseBranchRef string) error { +func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(newBranchName string, baseBranchRef string) error { commitsToCherryPick := lo.Filter(self.c.Model().Commits, func(commit *models.Commit, _ int) bool { return commit.Status == models.StatusUnpushed }) mustStash := IsWorkingTreeDirty(self.c.Model().Files) if mustStash { - if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + currentBranch); err != nil { + if err := self.c.Git().Stash.Push(fmt.Sprintf(self.c.Tr.AutoStashForNewBranch, newBranchName)); err != nil { return err } } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 07301af74..d345705bd 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -450,6 +450,7 @@ type TranslationSet struct { StashPrefix string AutoStashForUndo string AutoStashForCheckout string + AutoStashForNewBranch string Discard string DiscardChangesTitle string DiscardFileChangesTooltip string @@ -1545,6 +1546,7 @@ func EnglishTranslationSet() *TranslationSet { StashPrefix: "Auto-stashing changes for ", AutoStashForUndo: "Auto-stashing changes for undoing to %s", AutoStashForCheckout: "Auto-stashing changes for checking out %s", + AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s", Discard: "Discard", DiscardFileChangesTooltip: "View options for discarding changes to the selected file.", DiscardChangesTitle: "Discard changes",