allow adding whole diff to patch

this was causing a panic

add integration test for toggling all commit files
This commit is contained in:
Jesse Duffield 2022-03-23 23:15:54 +11:00
parent 5ded030a88
commit cc5d13c833
34 changed files with 103 additions and 28 deletions

View file

@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>o</kbd>: open file <kbd>o</kbd>: open file
<kbd>e</kbd>: edit file <kbd>e</kbd>: edit file
<kbd>space</kbd>: toggle file included in patch <kbd>space</kbd>: toggle file included in patch
<kbd>a</kbd>: toggle all files included in patch
<kbd>enter</kbd>: enter file to add selected lines to the patch (or toggle directory collapsed) <kbd>enter</kbd>: enter file to add selected lines to the patch (or toggle directory collapsed)
<kbd>`</kbd>: toggle file tree view <kbd>`</kbd>: toggle file tree view
</pre> </pre>

View file

@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>o</kbd>: open bestand <kbd>o</kbd>: open bestand
<kbd>e</kbd>: verander bestand <kbd>e</kbd>: verander bestand
<kbd>space</kbd>: toggle bestand inbegrepen in patch <kbd>space</kbd>: toggle bestand inbegrepen in patch
<kbd>a</kbd>: toggle all files included in patch
<kbd>enter</kbd>: enter bestand om geselecteerde regels toe te voegen aan de patch <kbd>enter</kbd>: enter bestand om geselecteerde regels toe te voegen aan de patch
<kbd>`</kbd>: toggle bestandsboom weergave <kbd>`</kbd>: toggle bestandsboom weergave
</pre> </pre>

View file

@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>o</kbd>: otwórz plik <kbd>o</kbd>: otwórz plik
<kbd>e</kbd>: edytuj plik <kbd>e</kbd>: edytuj plik
<kbd>space</kbd>: toggle file included in patch <kbd>space</kbd>: toggle file included in patch
<kbd>a</kbd>: toggle all files included in patch
<kbd>enter</kbd>: enter file to add selected lines to the patch (or toggle directory collapsed) <kbd>enter</kbd>: enter file to add selected lines to the patch (or toggle directory collapsed)
<kbd>`</kbd>: toggle file tree view <kbd>`</kbd>: toggle file tree view
</pre> </pre>

View file

@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>o</kbd>: 打开文件 <kbd>o</kbd>: 打开文件
<kbd>e</kbd>: 编辑文件 <kbd>e</kbd>: 编辑文件
<kbd>space</kbd>: 补丁中包含的切换文件 <kbd>space</kbd>: 补丁中包含的切换文件
<kbd>a</kbd>: toggle all files included in patch
<kbd>enter</kbd>: 输入文件以将所选行添加到补丁中(或切换目录折叠) <kbd>enter</kbd>: 输入文件以将所选行添加到补丁中(或切换目录折叠)
<kbd>`</kbd>: 切换文件树视图 <kbd>`</kbd>: 切换文件树视图
</pre> </pre>

View file

@ -52,6 +52,11 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) []
Handler: self.checkSelected(self.toggleForPatch), Handler: self.checkSelected(self.toggleForPatch),
Description: self.c.Tr.LcToggleAddToPatch, 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), Key: opts.GetKey(opts.Config.Universal.GoInto),
Handler: self.checkSelected(self.enter), 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 { func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error {
toggleTheFile := func() error { toggle := func() error {
if !self.git.Patch.PatchManager.Active() { return self.c.WithWaitingStatus(self.c.Tr.LcUpdatingPatch, func() error {
if err := self.startPatchManager(); err != nil { if !self.git.Patch.PatchManager.Active() {
return err if err := self.startPatchManager(); err != nil {
return err
}
} }
}
// if there is any file that hasn't been fully added we'll fully add everything, // if there is any file that hasn't been fully added we'll fully add everything,
// otherwise we'll remove everything // otherwise we'll remove everything
adding := node.AnyFile(func(file *models.CommitFile) bool { adding := node.AnyFile(func(file *models.CommitFile) bool {
return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRefName()) != patch.WHOLE return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRefName()) != patch.WHOLE
}) })
err := node.ForEachFile(func(file *models.CommitFile) error { err := node.ForEachFile(func(file *models.CommitFile) error {
if adding { if adding {
return self.git.Patch.PatchManager.AddFileWhole(file.Name) return self.git.Patch.PatchManager.AddFileWhole(file.Name)
} else { } else {
return self.git.Patch.PatchManager.RemoveFile(file.Name) 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() { 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, Prompt: self.c.Tr.DiscardPatchConfirm,
HandleConfirm: func() error { HandleConfirm: func() error {
self.git.Patch.PatchManager.Reset() 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 { func (self *CommitFilesController) startPatchManager() error {

View file

@ -275,6 +275,8 @@ type TranslationSet struct {
DiscardPatchConfirm string DiscardPatchConfirm string
CantPatchWhileRebasingError string CantPatchWhileRebasingError string
LcToggleAddToPatch string LcToggleAddToPatch string
LcToggleAllInPatch string
LcUpdatingPatch string
ViewPatchOptions string ViewPatchOptions string
PatchOptionsTitle string PatchOptionsTitle string
NoPatchError 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?", 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", CantPatchWhileRebasingError: "You cannot build a patch or run patch commands while in a merging or rebasing state",
LcToggleAddToPatch: "toggle file included in patch", LcToggleAddToPatch: "toggle file included in patch",
LcToggleAllInPatch: "toggle all files included in patch",
LcUpdatingPatch: "updating patch",
ViewPatchOptions: "view custom patch options", ViewPatchOptions: "view custom patch options",
PatchOptionsTitle: "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", NoPatchError: "No patch created yet. To start building a patch, use 'space' on a commit file or enter to add specific lines",

View file

@ -94,8 +94,7 @@ func RunTests(
continue continue
} }
fnWrapper(test, func(t *testing.T) error { fnWrapper(test, func(t *testing.T) error { //nolint: thelper
t.Helper()
speeds := getTestSpeeds(test.Speed, mode, speedEnv) speeds := getTestSpeeds(test.Speed, mode, speedEnv)
testPath := filepath.Join(testDir, test.Name) testPath := filepath.Join(testDir, test.Name)
actualRepoDir := filepath.Join(testPath, "actual") actualRepoDir := filepath.Join(testPath, "actual")

View file

@ -0,0 +1 @@
ref: refs/heads/master

View file

@ -0,0 +1,10 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[user]
email = CI@example.com
name = CI

View file

@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.

View file

@ -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

View file

@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 7028eaec19b2723b62690974057c92ba7d8c1b11 CI <CI@example.com> 1648038005 +1100 commit (initial): first commit
7028eaec19b2723b62690974057c92ba7d8c1b11 cf149a94a18c990b2c5cdd0cf15ec4880f51c8b0 CI <CI@example.com> 1648038005 +1100 commit: blah

View file

@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 7028eaec19b2723b62690974057c92ba7d8c1b11 CI <CI@example.com> 1648038005 +1100 commit (initial): first commit
7028eaec19b2723b62690974057c92ba7d8c1b11 cf149a94a18c990b2c5cdd0cf15ec4880f51c8b0 CI <CI@example.com> 1648038005 +1100 commit: blah

View file

@ -0,0 +1,4 @@
x<01>ÎM
Â@ @a×sŠÙ ÌADèªÇHÒ”
ß9ÛÇ·x²×új¼´„Èi¦ "=R ž]`\D<FØtê»Ù ®(i·ì²óœ\bÁ1å¹2¢¡O[÷ÓŽ“½<E2809C>ÓS¿T<C2BF>Mo²×‡Å
øíÀôÚ§šþÉ o´š×

View file

@ -0,0 +1 @@
cf149a94a18c990b2c5cdd0cf15ec4880f51c8b0

View file

@ -0,0 +1 @@
test3

View file

@ -0,0 +1 @@
{"KeyEvents":[{"Timestamp":624,"Mod":0,"Key":259,"Ch":0},{"Timestamp":813,"Mod":0,"Key":259,"Ch":0},{"Timestamp":1216,"Mod":0,"Key":13,"Ch":13},{"Timestamp":1841,"Mod":0,"Key":256,"Ch":97},{"Timestamp":2456,"Mod":0,"Key":258,"Ch":0},{"Timestamp":2624,"Mod":0,"Key":258,"Ch":0},{"Timestamp":2841,"Mod":0,"Key":256,"Ch":32},{"Timestamp":3600,"Mod":2,"Key":16,"Ch":16},{"Timestamp":4795,"Mod":0,"Key":258,"Ch":0},{"Timestamp":5193,"Mod":0,"Key":258,"Ch":0},{"Timestamp":5696,"Mod":0,"Key":13,"Ch":13},{"Timestamp":7345,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":272,"Height":74}]}

View file

@ -0,0 +1,23 @@
#!/bin/sh
set -e
cd $1
git init
git config user.email "CI@example.com"
git config user.name "CI"
git commit --allow-empty -m "first commit"
mkdir -p one/two/three
echo test1 > 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"

View file

@ -0,0 +1 @@
{ "description": "messing with our patch building flow in both flat and tree view", "speed": 10 }