1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-08 22:36:49 +02:00

Auto-stash if necessary when cherry-picking commits

This commit is contained in:
Stefan Haller
2025-07-02 17:04:12 +02:00
parent e7cb469fd0
commit 3f3e942f60
2 changed files with 21 additions and 0 deletions

View File

@ -78,7 +78,16 @@ func (self *CherryPickHelper) Paste() error {
}), }),
HandleConfirm: func() error { HandleConfirm: func() error {
return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) 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) 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) result := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
err := self.rebaseHelper.CheckMergeOrRebase(result) err := self.rebaseHelper.CheckMergeOrRebase(result)
if err != nil { if err != nil {
@ -96,7 +105,17 @@ func (self *CherryPickHelper) Paste() error {
if !isInCherryPick { if !isInCherryPick {
self.getData().DidPaste = true self.getData().DidPaste = true
self.rerender() 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 return nil
}) })
}, },

View File

@ -451,6 +451,7 @@ type TranslationSet struct {
AutoStashForCheckout string AutoStashForCheckout string
AutoStashForNewBranch string AutoStashForNewBranch string
AutoStashForMovingPatchToIndex string AutoStashForMovingPatchToIndex string
AutoStashForCherryPicking string
Discard string Discard string
DiscardChangesTitle string DiscardChangesTitle string
DiscardFileChangesTooltip string DiscardFileChangesTooltip string
@ -1547,6 +1548,7 @@ func EnglishTranslationSet() *TranslationSet {
AutoStashForCheckout: "Auto-stashing changes for checking out %s", AutoStashForCheckout: "Auto-stashing changes for checking out %s",
AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s", AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s",
AutoStashForMovingPatchToIndex: "Auto-stashing changes for moving custom patch to index from %s", AutoStashForMovingPatchToIndex: "Auto-stashing changes for moving custom patch to index from %s",
AutoStashForCherryPicking: "Auto-stashing changes for cherry-picking commits",
Discard: "Discard", Discard: "Discard",
DiscardFileChangesTooltip: "View options for discarding changes to the selected file.", DiscardFileChangesTooltip: "View options for discarding changes to the selected file.",
DiscardChangesTitle: "Discard changes", DiscardChangesTitle: "Discard changes",