Skip to content

Commit 6b1cab7

Browse files
committed
Auto-stash if necessary when reverting commits
1 parent dc795b5 commit 6b1cab7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/gui/controllers/local_commits_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,30 @@ func (self *LocalCommitsController) revert(commits []*models.Commit, start, end
873873
HandleConfirm: func() error {
874874
self.c.LogAction(self.c.Tr.Actions.RevertCommit)
875875
return self.c.WithWaitingStatusSync(self.c.Tr.RevertingStatus, func() error {
876+
mustStash := helpers.IsWorkingTreeDirty(self.c.Model().Files)
877+
878+
if mustStash {
879+
if err := self.c.Git().Stash.Push(self.c.Tr.AutoStashForReverting); err != nil {
880+
return err
881+
}
882+
}
883+
876884
result := self.c.Git().Commit.Revert(hashes, isMerge)
877885
if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(result, types.RefreshOptions{Mode: types.SYNC}); err != nil {
878886
return err
879887
}
880888
self.context().MoveSelection(len(commits))
881889
self.context().FocusLine()
890+
891+
if mustStash {
892+
if err := self.c.Git().Stash.Pop(0); err != nil {
893+
return err
894+
}
895+
self.c.Refresh(types.RefreshOptions{
896+
Scope: []types.RefreshableView{types.STASH, types.FILES},
897+
})
898+
}
899+
882900
return nil
883901
})
884902
},

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ type TranslationSet struct {
452452
AutoStashForNewBranch string
453453
AutoStashForMovingPatchToIndex string
454454
AutoStashForCherryPicking string
455+
AutoStashForReverting string
455456
Discard string
456457
DiscardChangesTitle string
457458
DiscardFileChangesTooltip string
@@ -1549,6 +1550,7 @@ func EnglishTranslationSet() *TranslationSet {
15491550
AutoStashForNewBranch: "Auto-stashing changes for creating new branch %s",
15501551
AutoStashForMovingPatchToIndex: "Auto-stashing changes for moving custom patch to index from %s",
15511552
AutoStashForCherryPicking: "Auto-stashing changes for cherry-picking commits",
1553+
AutoStashForReverting: "Auto-stashing changes for reverting commits",
15521554
Discard: "Discard",
15531555
DiscardFileChangesTooltip: "View options for discarding changes to the selected file.",
15541556
DiscardChangesTitle: "Discard changes",

0 commit comments

Comments
 (0)