Skip to content

Commit 2a7ce19

Browse files
committed
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.
1 parent 908975c commit 2a7ce19

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pkg/gui/controllers/helpers/refs_helper.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
355355
Title: self.c.Tr.AutoStashTitle,
356356
Prompt: self.c.Tr.AutoStashPrompt,
357357
HandleConfirm: func() error {
358-
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + newBranchName); err != nil {
358+
if err := self.c.Git().Stash.Push(fmt.Sprintf(self.c.Tr.AutoStashForNewBranch, newBranchName)); err != nil {
359359
return err
360360
}
361361
if err := newBranchFunc(newBranchName, from); err != nil {
@@ -389,7 +389,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
389389
return err
390390
}
391391

392-
withNewBranchNamePrompt := func(baseBranchName string, f func(string, string) error) error {
392+
withNewBranchNamePrompt := func(baseBranchName string, f func(string) error) error {
393393
prompt := utils.ResolvePlaceholderString(
394394
self.c.Tr.NewBranchNameBranchOff,
395395
map[string]string{
@@ -408,7 +408,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
408408
self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch)
409409
newBranchName := SanitizedBranchName(response)
410410
return self.c.WithWaitingStatus(self.c.Tr.MovingCommitsToNewBranchStatus, func(gocui.Task) error {
411-
return f(currentBranch.Name, newBranchName)
411+
return f(newBranchName)
412412
})
413413
},
414414
})
@@ -447,8 +447,8 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
447447
{
448448
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchFromBaseItem, shortBaseBranchName),
449449
OnPress: func() error {
450-
return withNewBranchNamePrompt(shortBaseBranchName, func(currentBranch string, newBranchName string) error {
451-
return self.moveCommitsToNewBranchOffOfMainBranch(currentBranch, newBranchName, baseBranchRef)
450+
return withNewBranchNamePrompt(shortBaseBranchName, func(newBranchName string) error {
451+
return self.moveCommitsToNewBranchOffOfMainBranch(newBranchName, baseBranchRef)
452452
})
453453
},
454454
},
@@ -462,14 +462,14 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
462462
})
463463
}
464464

465-
func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(currentBranch string, newBranchName string) error {
465+
func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(newBranchName string) error {
466466
if err := self.c.Git().Branch.NewWithoutCheckout(newBranchName, "HEAD"); err != nil {
467467
return err
468468
}
469469

470470
mustStash := IsWorkingTreeDirty(self.c.Model().Files)
471471
if mustStash {
472-
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + currentBranch); err != nil {
472+
if err := self.c.Git().Stash.Push(fmt.Sprintf(self.c.Tr.AutoStashForNewBranch, newBranchName)); err != nil {
473473
return err
474474
}
475475
}
@@ -495,14 +495,14 @@ func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(currentBran
495495
return nil
496496
}
497497

498-
func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(currentBranch string, newBranchName string, baseBranchRef string) error {
498+
func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(newBranchName string, baseBranchRef string) error {
499499
commitsToCherryPick := lo.Filter(self.c.Model().Commits, func(commit *models.Commit, _ int) bool {
500500
return commit.Status == models.StatusUnpushed
501501
})
502502

503503
mustStash := IsWorkingTreeDirty(self.c.Model().Files)
504504
if mustStash {
505-
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + currentBranch); err != nil {
505+
if err := self.c.Git().Stash.Push(fmt.Sprintf(self.c.Tr.AutoStashForNewBranch, newBranchName)); err != nil {
506506
return err
507507
}
508508
}

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ type TranslationSet struct {
450450
StashPrefix string
451451
AutoStashForUndo string
452452
AutoStashForCheckout string
453+
AutoStashForNewBranch string
453454
Discard string
454455
DiscardChangesTitle string
455456
DiscardFileChangesTooltip string
@@ -1545,6 +1546,7 @@ func EnglishTranslationSet() *TranslationSet {
15451546
StashPrefix: "Auto-stashing changes for ",
15461547
AutoStashForUndo: "Auto-stashing changes for undoing to %s",
15471548
AutoStashForCheckout: "Auto-stashing changes for checking out %s",
1549+
AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s",
15481550
Discard: "Discard",
15491551
DiscardFileChangesTooltip: "View options for discarding changes to the selected file.",
15501552
DiscardChangesTitle: "Discard changes",

0 commit comments

Comments
 (0)