Skip to content

Commit 3f3e942

Browse files
committed
Auto-stash if necessary when cherry-picking commits
1 parent e7cb469 commit 3f3e942

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/gui/controllers/helpers/cherry_pick_helper.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ func (self *CherryPickHelper) Paste() error {
7878
}),
7979
HandleConfirm: func() error {
8080
return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) error {
81+
mustStash := IsWorkingTreeDirty(self.c.Model().Files)
82+
8183
self.c.LogAction(self.c.Tr.Actions.CherryPick)
84+
85+
if mustStash {
86+
if err := self.c.Git().Stash.Push(self.c.Tr.AutoStashForCherryPicking); err != nil {
87+
return err
88+
}
89+
}
90+
8291
result := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
8392
err := self.rebaseHelper.CheckMergeOrRebase(result)
8493
if err != nil {
@@ -96,7 +105,17 @@ func (self *CherryPickHelper) Paste() error {
96105
if !isInCherryPick {
97106
self.getData().DidPaste = true
98107
self.rerender()
108+
109+
if mustStash {
110+
if err := self.c.Git().Stash.Pop(0); err != nil {
111+
return err
112+
}
113+
self.c.Refresh(types.RefreshOptions{
114+
Scope: []types.RefreshableView{types.STASH, types.FILES},
115+
})
116+
}
99117
}
118+
100119
return nil
101120
})
102121
},

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ type TranslationSet struct {
451451
AutoStashForCheckout string
452452
AutoStashForNewBranch string
453453
AutoStashForMovingPatchToIndex string
454+
AutoStashForCherryPicking string
454455
Discard string
455456
DiscardChangesTitle string
456457
DiscardFileChangesTooltip string
@@ -1547,6 +1548,7 @@ func EnglishTranslationSet() *TranslationSet {
15471548
AutoStashForCheckout: "Auto-stashing changes for checking out %s",
15481549
AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s",
15491550
AutoStashForMovingPatchToIndex: "Auto-stashing changes for moving custom patch to index from %s",
1551+
AutoStashForCherryPicking: "Auto-stashing changes for cherry-picking commits",
15501552
Discard: "Discard",
15511553
DiscardFileChangesTooltip: "View options for discarding changes to the selected file.",
15521554
DiscardChangesTitle: "Discard changes",

0 commit comments

Comments
 (0)