mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 22:33:07 +02:00
When pressing a
to stage all files, don't include untracked files when showing only tracked files (#4779)
- **PR Description** This is very similar to what we did for pressing space in #4386; we forgot that the "stage all" command has the same issue. Also, fix two other commands that stage all files under the hood: - when continuing a rebase after resolving conflicts, we auto-stage all files, but in this case we never want to include untracked files, regardless of the filter - likewise, pressing ctrl-f to find a base commit for fixup stages all files for convenience, but again, this should only stage files that are already tracked
This commit is contained in:
@ -49,8 +49,10 @@ func (self *WorkingTreeCommands) StageFiles(paths []string, extraArgs []string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StageAll stages all files
|
// StageAll stages all files
|
||||||
func (self *WorkingTreeCommands) StageAll() error {
|
func (self *WorkingTreeCommands) StageAll(onlyTrackedFiles bool) error {
|
||||||
cmdArgs := NewGitCmd("add").Arg("-A").ToArgv()
|
cmdArgs := NewGitCmd("add").
|
||||||
|
ArgIfElse(onlyTrackedFiles, "-u", "-A").
|
||||||
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).Run()
|
return self.cmd.New(cmdArgs).Run()
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,8 @@ func (self *FilesController) toggleStagedAllWithLock() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
|
onlyTrackedFiles := self.context().GetFilter() == filetree.DisplayTracked
|
||||||
|
if err := self.c.Git().WorkingTree.StageAll(onlyTrackedFiles); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,7 +133,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
|
|||||||
Prompt: self.c.Tr.HunksWithOnlyAddedLinesWarning,
|
Prompt: self.c.Tr.HunksWithOnlyAddedLinesWarning,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
if !hasStagedChanges {
|
if !hasStagedChanges {
|
||||||
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
|
if err := self.c.Git().WorkingTree.StageAll(true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
|
self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
|
||||||
|
@ -244,7 +244,7 @@ func (self *MergeAndRebaseHelper) PromptToContinueRebase() error {
|
|||||||
Prompt: self.c.Tr.UnstagedFilesAfterConflictsResolved,
|
Prompt: self.c.Tr.UnstagedFilesAfterConflictsResolved,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
||||||
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
|
if err := self.c.Git().WorkingTree.StageAll(true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ func (self *WorkingTreeHelper) promptToStageAllAndRetry(retry func() error) erro
|
|||||||
Prompt: self.c.Tr.NoFilesStagedPrompt,
|
Prompt: self.c.Tr.NoFilesStagedPrompt,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
||||||
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
|
if err := self.c.Git().WorkingTree.StageAll(false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
self.syncRefresh()
|
self.syncRefresh()
|
||||||
@ -228,7 +228,7 @@ func (self *WorkingTreeHelper) prepareFilesForCommit() error {
|
|||||||
noStagedFiles := !self.AnyStagedFiles()
|
noStagedFiles := !self.AnyStagedFiles()
|
||||||
if noStagedFiles && self.c.UserConfig().Gui.SkipNoStagedFilesWarning {
|
if noStagedFiles && self.c.UserConfig().Gui.SkipNoStagedFilesWarning {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
||||||
err := self.c.Git().WorkingTree.StageAll()
|
err := self.c.Git().WorkingTree.StageAll(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package filter_and_search
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var StageAllStagesOnlyTrackedFilesInTrackedOnlyFilter = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Staging all files in tracked only view should stage only tracked files",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.CreateFileAndAdd("file-tracked", "foo")
|
||||||
|
|
||||||
|
shell.Commit("first commit")
|
||||||
|
|
||||||
|
shell.CreateFile("file-untracked", "bar")
|
||||||
|
shell.UpdateFile("file-tracked", "baz")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Files().
|
||||||
|
Focus().
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /").IsSelected(),
|
||||||
|
Equals(" M file-tracked"),
|
||||||
|
Equals(" ?? file-untracked"),
|
||||||
|
).
|
||||||
|
Press(keys.Files.OpenStatusFilter).
|
||||||
|
Tap(func() {
|
||||||
|
t.ExpectPopup().Menu().
|
||||||
|
Title(Equals("Filtering")).
|
||||||
|
Select(Contains("Show only tracked files")).
|
||||||
|
Confirm()
|
||||||
|
}).
|
||||||
|
Lines(
|
||||||
|
Equals(" M file-tracked"),
|
||||||
|
).
|
||||||
|
Press(keys.Files.ToggleStagedAll).
|
||||||
|
Press(keys.Files.OpenStatusFilter).
|
||||||
|
Tap(func() {
|
||||||
|
t.ExpectPopup().Menu().
|
||||||
|
Title(Equals("Filtering")).
|
||||||
|
Select(Contains("No filter")).
|
||||||
|
Confirm()
|
||||||
|
}).
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /").IsSelected(),
|
||||||
|
Equals(" M file-tracked"), // 'M' is now in the left column, so file is staged
|
||||||
|
Equals(" ?? file-untracked"),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
@ -229,6 +229,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
filter_and_search.NestedFilter,
|
filter_and_search.NestedFilter,
|
||||||
filter_and_search.NestedFilterTransient,
|
filter_and_search.NestedFilterTransient,
|
||||||
filter_and_search.NewSearch,
|
filter_and_search.NewSearch,
|
||||||
|
filter_and_search.StageAllStagesOnlyTrackedFilesInTrackedOnlyFilter,
|
||||||
filter_and_search.StagingFolderStagesOnlyTrackedFilesInTrackedOnlyFilter,
|
filter_and_search.StagingFolderStagesOnlyTrackedFilesInTrackedOnlyFilter,
|
||||||
filter_by_author.SelectAuthor,
|
filter_by_author.SelectAuthor,
|
||||||
filter_by_author.TypeAuthor,
|
filter_by_author.TypeAuthor,
|
||||||
|
Reference in New Issue
Block a user