diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-23 23:15:54 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-23 23:36:58 +1100 |
commit | cc5d13c833daaba4a27507ce33e5de90ed8b1567 (patch) | |
tree | c8e685ce9bc39f1532a93895f368a8d4b2eb41bf /pkg | |
parent | 5ded030a884b6358da34ddd5b855e0f2cb005d24 (diff) |
allow adding whole diff to patch
this was causing a panic
add integration test for toggling all commit files
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/controllers/commits_files_controller.go | 63 | ||||
-rw-r--r-- | pkg/i18n/english.go | 4 | ||||
-rw-r--r-- | pkg/integration/integration.go | 3 |
3 files changed, 43 insertions, 27 deletions
diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 978d6c6a7..65b930ef6 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -53,6 +53,11 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) [] Description: self.c.Tr.LcToggleAddToPatch, }, { + Key: opts.GetKey(opts.Config.Files.ToggleStagedAll), + Handler: self.checkSelected(self.toggleAllForPatch), + Description: self.c.Tr.LcToggleAllInPatch, + }, + { Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.checkSelected(self.enter), Description: self.c.Tr.LcEnterFile, @@ -150,35 +155,37 @@ func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error { } func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error { - toggleTheFile := func() error { - if !self.git.Patch.PatchManager.Active() { - if err := self.startPatchManager(); err != nil { - return err + toggle := func() error { + return self.c.WithWaitingStatus(self.c.Tr.LcUpdatingPatch, func() error { + if !self.git.Patch.PatchManager.Active() { + if err := self.startPatchManager(); err != nil { + return err + } } - } - // if there is any file that hasn't been fully added we'll fully add everything, - // otherwise we'll remove everything - adding := node.AnyFile(func(file *models.CommitFile) bool { - return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRefName()) != patch.WHOLE - }) + // if there is any file that hasn't been fully added we'll fully add everything, + // otherwise we'll remove everything + adding := node.AnyFile(func(file *models.CommitFile) bool { + return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRefName()) != patch.WHOLE + }) - err := node.ForEachFile(func(file *models.CommitFile) error { - if adding { - return self.git.Patch.PatchManager.AddFileWhole(file.Name) - } else { - return self.git.Patch.PatchManager.RemoveFile(file.Name) + err := node.ForEachFile(func(file *models.CommitFile) error { + if adding { + return self.git.Patch.PatchManager.AddFileWhole(file.Name) + } else { + return self.git.Patch.PatchManager.RemoveFile(file.Name) + } + }) + if err != nil { + return self.c.Error(err) } - }) - if err != nil { - return self.c.Error(err) - } - if self.git.Patch.PatchManager.IsEmpty() { - self.git.Patch.PatchManager.Reset() - } + if self.git.Patch.PatchManager.IsEmpty() { + self.git.Patch.PatchManager.Reset() + } - return self.c.PostRefreshUpdate(self.context()) + return self.c.PostRefreshUpdate(self.context()) + }) } if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRefName() { @@ -187,12 +194,18 @@ func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) Prompt: self.c.Tr.DiscardPatchConfirm, HandleConfirm: func() error { self.git.Patch.PatchManager.Reset() - return toggleTheFile() + return toggle() }, }) } - return toggleTheFile() + return toggle() +} + +func (self *CommitFilesController) toggleAllForPatch(_ *filetree.CommitFileNode) error { + // not a fan of type assertions but this will be fixed very soon thanks to generics + root := self.context().CommitFileTreeViewModel.Tree().(*filetree.CommitFileNode) + return self.toggleForPatch(root) } func (self *CommitFilesController) startPatchManager() error { diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index aba4e9368..db25cf0a6 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -275,6 +275,8 @@ type TranslationSet struct { DiscardPatchConfirm string CantPatchWhileRebasingError string LcToggleAddToPatch string + LcToggleAllInPatch string + LcUpdatingPatch string ViewPatchOptions string PatchOptionsTitle string NoPatchError string @@ -846,6 +848,8 @@ func EnglishTranslationSet() TranslationSet { DiscardPatchConfirm: "You can only build a patch from one commit/stash-entry at a time. Discard current patch?", CantPatchWhileRebasingError: "You cannot build a patch or run patch commands while in a merging or rebasing state", LcToggleAddToPatch: "toggle file included in patch", + LcToggleAllInPatch: "toggle all files included in patch", + LcUpdatingPatch: "updating patch", ViewPatchOptions: "view custom patch options", PatchOptionsTitle: "Patch Options", NoPatchError: "No patch created yet. To start building a patch, use 'space' on a commit file or enter to add specific lines", diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index 86049a230..bb2d7a0b0 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -94,8 +94,7 @@ func RunTests( continue } - fnWrapper(test, func(t *testing.T) error { - t.Helper() + fnWrapper(test, func(t *testing.T) error { //nolint: thelper speeds := getTestSpeeds(test.Speed, mode, speedEnv) testPath := filepath.Join(testDir, test.Name) actualRepoDir := filepath.Join(testPath, "actual") |