From d2675b7deaf568814a2e832cbd5fe509db92162b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 12 Oct 2026 18:36:03 +0200 Subject: [PATCH] Extract stageAllScope from toggleStagedAllWithLock Whether stage-all may be used is going to depend on what it stages. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/controllers/files_controller.go | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index e4c42279b..89e2f1166 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -993,22 +993,44 @@ func (self *FilesController) toggleStagedAll() error { return nil } +// What staging all files stages +type stageAllScope int + +const ( + // Only the files that are visible, because a text filter is active + stageAllVisibleFiles stageAllScope = iota + // Only tracked files, because only those are shown + stageAllTrackedFiles + stageAllFiles +) + +func (self *FilesController) stageAllScope() stageAllScope { + if self.context().IsFiltering() { + return stageAllVisibleFiles + } + if self.context().GetStatusFilter() == filetree.DisplayTracked { + return stageAllTrackedFiles + } + return stageAllFiles +} + func (self *FilesController) toggleStagedAllWithLock() error { root := self.context().FileTreeViewModel.GetRoot() stage := func(unstagedNodes []*filetree.FileNode) error { - if self.context().IsFiltering() { - // When filtering, only stage visible files + switch self.stageAllScope() { + case stageAllVisibleFiles: var paths []string _ = root.ForEachFile(func(file *models.File) error { paths = append(paths, file.Path) return nil }) return self.c.Git().WorkingTree.StageFiles(paths, nil) + case stageAllTrackedFiles: + return self.c.Git().WorkingTree.StageAll(true) + default: + return self.c.Git().WorkingTree.StageAll(false) } - - onlyTrackedFiles := self.context().GetStatusFilter() == filetree.DisplayTracked - return self.c.Git().WorkingTree.StageAll(onlyTrackedFiles) } unstage := func(nodes []*filetree.FileNode) error {