diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index acac130a4..662631386 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct o: open file e: edit file space: toggle file included in patch + a: toggle all files included in patch enter: enter file to add selected lines to the patch (or toggle directory collapsed) `: toggle file tree view diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 428d9507b..dd9c45ad2 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct o: open bestand e: verander bestand space: toggle bestand inbegrepen in patch + a: toggle all files included in patch enter: enter bestand om geselecteerde regels toe te voegen aan de patch `: toggle bestandsboom weergave diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index fd26ea20d..2d032e5e3 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct o: otwórz plik e: edytuj plik space: toggle file included in patch + a: toggle all files included in patch enter: enter file to add selected lines to the patch (or toggle directory collapsed) `: toggle file tree view diff --git a/docs/keybindings/Keybindings_zh.md b/docs/keybindings/Keybindings_zh.md index c075a7879..12b9a90f7 100644 --- a/docs/keybindings/Keybindings_zh.md +++ b/docs/keybindings/Keybindings_zh.md @@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct o: 打开文件 e: 编辑文件 space: 补丁中包含的切换文件 + a: toggle all files included in patch enter: 输入文件以将所选行添加到补丁中(或切换目录折叠) `: 切换文件树视图 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 @@ -52,6 +52,11 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) [] Handler: self.checkSelected(self.toggleForPatch), 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), @@ -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 self.git.Patch.PatchManager.IsEmpty() { + self.git.Patch.PatchManager.Reset() + } + + return self.c.PostRefreshUpdate(self.context()) }) - if err != nil { - return self.c.Error(err) - } - - if self.git.Patch.PatchManager.IsEmpty() { - self.git.Patch.PatchManager.Reset() - } - - 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") diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/COMMIT_EDITMSG b/test/integration/patchBuildingToggleAll/expected/.git_keep/COMMIT_EDITMSG new file mode 100644 index 000000000..907b30816 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/COMMIT_EDITMSG @@ -0,0 +1 @@ +blah diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/FETCH_HEAD b/test/integration/patchBuildingToggleAll/expected/.git_keep/FETCH_HEAD new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/HEAD b/test/integration/patchBuildingToggleAll/expected/.git_keep/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/config b/test/integration/patchBuildingToggleAll/expected/.git_keep/config new file mode 100644 index 000000000..8ae104545 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/config @@ -0,0 +1,10 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[user] + email = CI@example.com + name = CI diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/description b/test/integration/patchBuildingToggleAll/expected/.git_keep/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/index b/test/integration/patchBuildingToggleAll/expected/.git_keep/index new file mode 100644 index 000000000..291d34ebe Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/index differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/info/exclude b/test/integration/patchBuildingToggleAll/expected/.git_keep/info/exclude new file mode 100644 index 000000000..8e9f2071f --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/info/exclude @@ -0,0 +1,7 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ +.DS_Store diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/logs/HEAD b/test/integration/patchBuildingToggleAll/expected/.git_keep/logs/HEAD new file mode 100644 index 000000000..30dd712e1 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/logs/HEAD @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 7028eaec19b2723b62690974057c92ba7d8c1b11 CI 1648038005 +1100 commit (initial): first commit +7028eaec19b2723b62690974057c92ba7d8c1b11 cf149a94a18c990b2c5cdd0cf15ec4880f51c8b0 CI 1648038005 +1100 commit: blah diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/logs/refs/heads/master b/test/integration/patchBuildingToggleAll/expected/.git_keep/logs/refs/heads/master new file mode 100644 index 000000000..30dd712e1 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/logs/refs/heads/master @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 7028eaec19b2723b62690974057c92ba7d8c1b11 CI 1648038005 +1100 commit (initial): first commit +7028eaec19b2723b62690974057c92ba7d8c1b11 cf149a94a18c990b2c5cdd0cf15ec4880f51c8b0 CI 1648038005 +1100 commit: blah diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 new file mode 100644 index 000000000..f74bf2335 Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/41/05b6da4ccc191a4abd24b1ffac6a2031534c0b b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/41/05b6da4ccc191a4abd24b1ffac6a2031534c0b new file mode 100644 index 000000000..a35700d0e Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/41/05b6da4ccc191a4abd24b1ffac6a2031534c0b differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/44/eb4bd0e7419049a8e4176945786c20dae60d7c b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/44/eb4bd0e7419049a8e4176945786c20dae60d7c new file mode 100644 index 000000000..3a7adb136 Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/44/eb4bd0e7419049a8e4176945786c20dae60d7c differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 new file mode 100644 index 000000000..adf64119a Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/4f/346f1ad5ba2917da2109e2eaa2f2dfbb86f10f b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/4f/346f1ad5ba2917da2109e2eaa2f2dfbb86f10f new file mode 100644 index 000000000..953241815 Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/4f/346f1ad5ba2917da2109e2eaa2f2dfbb86f10f differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/68/bbd52379d849022495dcfd11b13f2fb3103d37 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/68/bbd52379d849022495dcfd11b13f2fb3103d37 new file mode 100644 index 000000000..15e2a131e Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/68/bbd52379d849022495dcfd11b13f2fb3103d37 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/70/28eaec19b2723b62690974057c92ba7d8c1b11 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/70/28eaec19b2723b62690974057c92ba7d8c1b11 new file mode 100644 index 000000000..a3f20d2e9 Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/70/28eaec19b2723b62690974057c92ba7d8c1b11 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/83/90c32b5e687b97e242da46498b574ace0e1eb5 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/83/90c32b5e687b97e242da46498b574ace0e1eb5 new file mode 100644 index 000000000..be495f399 Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/83/90c32b5e687b97e242da46498b574ace0e1eb5 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/98/1651deb012f8e684dd306c1f5bf8edd5c3db67 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/98/1651deb012f8e684dd306c1f5bf8edd5c3db67 new file mode 100644 index 000000000..0db8d9831 Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/98/1651deb012f8e684dd306c1f5bf8edd5c3db67 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 new file mode 100644 index 000000000..285df3e5f Binary files /dev/null and b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 differ diff --git a/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/cf/149a94a18c990b2c5cdd0cf15ec4880f51c8b0 b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/cf/149a94a18c990b2c5cdd0cf15ec4880f51c8b0 new file mode 100644 index 000000000..5d9dcc080 --- /dev/null +++ b/test/integration/patchBuildingToggleAll/expected/.git_keep/objects/cf/149a94a18c990b2c5cdd0cf15ec4880f51c8b0 @@ -0,0 +1,4 @@ +xM +@ @as ADHҔ +[9ǷxjSi "=R ]`\D one/two/three/file1 +echo test2 > one/two/three/file2 +echo test3 > one/two/three/file3 +echo test4 > one/two/three/file4 +echo test5 > one/two/file1 +echo test6 > one/two/file2 + +git add . +git commit -m "blah" diff --git a/test/integration/patchBuildingToggleAll/test.json b/test/integration/patchBuildingToggleAll/test.json new file mode 100644 index 000000000..1804ea8aa --- /dev/null +++ b/test/integration/patchBuildingToggleAll/test.json @@ -0,0 +1 @@ +{ "description": "messing with our patch building flow in both flat and tree view", "speed": 10 }