diff options
author | Aaron Hoffman <kd0sgh@gmail.com> | 2024-01-28 09:15:29 -0600 |
---|---|---|
committer | Aaron Hoffman <kd0sgh@gmail.com> | 2024-02-13 09:10:15 -0600 |
commit | 15d5261933912f0665ca1920f5131dce9cc2dbb3 (patch) | |
tree | 434e054045aaa72d1bad42cfd517c6afe5af213b /pkg/gui | |
parent | beb730a9e6f9113db3cb22b222f4858f95dc4d55 (diff) |
Support range select removing files from a commit
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/controllers/commits_files_controller.go | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 647d6594b..326a8a6d3 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -50,8 +50,8 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) [] }, { Key: opts.GetKey(opts.Config.Universal.Remove), - Handler: self.withItem(self.discard), - GetDisabledReason: self.require(self.singleItemSelected()), + Handler: self.withItems(self.discard), + GetDisabledReason: self.require(self.itemsSelected()), Description: self.c.Tr.Remove, Tooltip: self.c.Tr.DiscardOldFileChangeTooltip, DisplayOnScreen: true, @@ -176,43 +176,56 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) } -func (self *CommitFilesController) discard(node *filetree.CommitFileNode) error { +func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error { parentContext, ok := self.c.CurrentContext().GetParentContext() if !ok || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY { return self.c.ErrorMsg(self.c.Tr.CanOnlyDiscardFromLocalCommits) } - if node.File == nil { - return self.c.ErrorMsg(self.c.Tr.DiscardNotSupportedForDirectory) - } - if ok, err := self.c.Helpers().PatchBuilding.ValidateNormalWorkingTreeState(); !ok { return err } - prompt := self.c.Tr.DiscardFileChangesPrompt - if node.File.Added() { - prompt = self.c.Tr.DiscardAddedFileChangesPrompt - } else if node.File.Deleted() { - prompt = self.c.Tr.DiscardDeletedFileChangesPrompt - } + removeFileRange := func() error { + return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error { + selectedNodes = normalisedSelectedCommitFileNodes(selectedNodes) + + return self.c.Confirm(types.ConfirmOpts{ + Title: self.c.Tr.DiscardFileChangesTitle, + Prompt: self.c.Tr.DiscardFileChangesPrompt, + HandleConfirm: func() error { + var filePaths []string + + // Reset the current patch if there is one. + if self.c.Git().Patch.PatchBuilder.Active() { + self.c.Git().Patch.PatchBuilder.Reset() + if err := self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI}); err != nil { + return err + } + } - return self.c.Confirm(types.ConfirmOpts{ - Title: self.c.Tr.DiscardFileChangesTitle, - Prompt: prompt, - HandleConfirm: func() error { - return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error { - self.c.LogAction(self.c.Tr.Actions.DiscardOldFileChange) - if err := self.c.Git().Rebase.DiscardOldFileChanges(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), node.GetPath()); err != nil { + for _, node := range selectedNodes { + err := node.ForEachFile(func(file *models.CommitFile) error { + filePaths = append(filePaths, file.GetPath()) + return nil + }) + if err != nil { + return self.c.Error(err) + } + } + + err := self.c.Git().Rebase.DiscardOldFileChanges(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), filePaths) if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil { return err } - } - return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI}) + return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI}) + }, }) - }, - }) + }) + } + + return removeFileRange() } func (self *CommitFilesController) open(node *filetree.CommitFileNode) error { |