mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02:00
allow adding whole diff to patch
this was causing a panic add integration test for toggling all commit files
This commit is contained in:
parent
5ded030a88
commit
cc5d13c833
@ -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>e</kbd>: edit file
|
||||
<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>`</kbd>: toggle file tree view
|
||||
</pre>
|
||||
|
@ -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>e</kbd>: verander bestand
|
||||
<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>`</kbd>: toggle bestandsboom weergave
|
||||
</pre>
|
||||
|
@ -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>e</kbd>: edytuj plik
|
||||
<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>`</kbd>: toggle file tree view
|
||||
</pre>
|
||||
|
@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
||||
<kbd>o</kbd>: 打开文件
|
||||
<kbd>e</kbd>: 编辑文件
|
||||
<kbd>space</kbd>: 补丁中包含的切换文件
|
||||
<kbd>a</kbd>: toggle all files included in patch
|
||||
<kbd>enter</kbd>: 输入文件以将所选行添加到补丁中(或切换目录折叠)
|
||||
<kbd>`</kbd>: 切换文件树视图
|
||||
</pre>
|
||||
|
@ -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 {
|
||||
|
@ -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",
|
||||
|
@ -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")
|
||||
|
@ -0,0 +1 @@
|
||||
blah
|
@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
@ -0,0 +1,10 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
[user]
|
||||
email = CI@example.com
|
||||
name = CI
|
@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
BIN
test/integration/patchBuildingToggleAll/expected/.git_keep/index
Normal file
BIN
test/integration/patchBuildingToggleAll/expected/.git_keep/index
Normal file
Binary file not shown.
@ -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
|
@ -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
|
@ -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
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
x�ÎM
|
||||
Â@@a×sŠÙ’ÌADèªÇHÒ”
|
||||
[Êß9‚ÛÇ·x²×új¼´SÕ„Èi¦ "=R ž]`\’D<FØtê»Ù®(i·ì²óœ\`Èb–Á1å¹2¢¡O[÷ÓŽ“½�ÓS¿T�Mo²×‡Å
|
||||
øíÀôÚ§šþÉ
o´š×8ß
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
cf149a94a18c990b2c5cdd0cf15ec4880f51c8b0
|
@ -0,0 +1 @@
|
||||
test3
|
1
test/integration/patchBuildingToggleAll/recording.json
Normal file
1
test/integration/patchBuildingToggleAll/recording.json
Normal 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}]}
|
23
test/integration/patchBuildingToggleAll/setup.sh
Normal file
23
test/integration/patchBuildingToggleAll/setup.sh
Normal 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"
|
1
test/integration/patchBuildingToggleAll/test.json
Normal file
1
test/integration/patchBuildingToggleAll/test.json
Normal file
@ -0,0 +1 @@
|
||||
{ "description": "messing with our patch building flow in both flat and tree view", "speed": 10 }
|
Loading…
x
Reference in New Issue
Block a user