From 3f3e942f60282170b2ca73586a5b09955548b815 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 2 Jul 2025 17:04:12 +0200 Subject: [PATCH] Auto-stash if necessary when cherry-picking commits --- .../controllers/helpers/cherry_pick_helper.go | 19 +++++++++++++++++++ pkg/i18n/english.go | 2 ++ 2 files changed, 21 insertions(+) diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 5b96dc84c..3b9232340 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -78,7 +78,16 @@ func (self *CherryPickHelper) Paste() error { }), HandleConfirm: func() error { return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) error { + mustStash := IsWorkingTreeDirty(self.c.Model().Files) + self.c.LogAction(self.c.Tr.Actions.CherryPick) + + if mustStash { + if err := self.c.Git().Stash.Push(self.c.Tr.AutoStashForCherryPicking); err != nil { + return err + } + } + result := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits) err := self.rebaseHelper.CheckMergeOrRebase(result) if err != nil { @@ -96,7 +105,17 @@ func (self *CherryPickHelper) Paste() error { if !isInCherryPick { self.getData().DidPaste = true self.rerender() + + if mustStash { + if err := self.c.Git().Stash.Pop(0); err != nil { + return err + } + self.c.Refresh(types.RefreshOptions{ + Scope: []types.RefreshableView{types.STASH, types.FILES}, + }) + } } + return nil }) }, diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index e0b2f1ed3..85c075f7b 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -451,6 +451,7 @@ type TranslationSet struct { AutoStashForCheckout string AutoStashForNewBranch string AutoStashForMovingPatchToIndex string + AutoStashForCherryPicking string Discard string DiscardChangesTitle string DiscardFileChangesTooltip string @@ -1547,6 +1548,7 @@ func EnglishTranslationSet() *TranslationSet { AutoStashForCheckout: "Auto-stashing changes for checking out %s", AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s", AutoStashForMovingPatchToIndex: "Auto-stashing changes for moving custom patch to index from %s", + AutoStashForCherryPicking: "Auto-stashing changes for cherry-picking commits", Discard: "Discard", DiscardFileChangesTooltip: "View options for discarding changes to the selected file.", DiscardChangesTitle: "Discard changes",