From 6dca12131f4f5d8fc0fd36ce62bd396b04eeceb1 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Sat, 25 Jul 2026 21:43:13 +0800 Subject: [PATCH] Refactor Ignore/Exclude to accept multiple filenames The gitignore-applier layer now takes a slice, looping over paths. The files_controller plumbing still feeds a single-element slice so behavior is unchanged for the single-file case; this prepares for wiring the binding up to multi-select. --- pkg/commands/git_commands/working_tree.go | 22 ++++++++++++++++------ pkg/gui/controllers/files_controller.go | 8 ++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index d296858f6..dbe0346ac 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -367,19 +367,29 @@ func escapeFilename(filename string) string { return "/" + re.ReplaceAllString(filename, `\${0}`) } -// Ignore adds a file to the gitignore for the repo -func (self *WorkingTreeCommands) Ignore(filename string) error { - return self.os.AppendLineToFile(".gitignore", escapeFilename(filename)) +// Ignore adds the given files to the gitignore for the repo +func (self *WorkingTreeCommands) Ignore(filenames []string) error { + for _, filename := range filenames { + if err := self.os.AppendLineToFile(".gitignore", escapeFilename(filename)); err != nil { + return err + } + } + return nil } -// Exclude adds a file to the .git/info/exclude for the repo -func (self *WorkingTreeCommands) Exclude(filename string) error { +// Exclude adds the given files to the .git/info/exclude for the repo +func (self *WorkingTreeCommands) Exclude(filenames []string) error { infoDir := filepath.Join(self.repoPaths.repoGitDirPath, "info") if err := os.MkdirAll(infoDir, 0o755); err != nil { return err } excludeFile := filepath.Join(infoDir, "exclude") - return self.os.AppendLineToFile(excludeFile, escapeFilename(filename)) + for _, filename := range filenames { + if err := self.os.AppendLineToFile(excludeFile, escapeFilename(filename)); err != nil { + return err + } + } + return nil } // WorktreeFileDiff returns the diff of a file diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 656da1bf5..a133dac72 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -1020,7 +1020,9 @@ func (self *FilesController) ignore(node *filetree.FileNode) error { if node.GetPath() == ".gitignore" { return errors.New(self.c.Tr.Actions.IgnoreFileErr) } - return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, self.c.Git().WorkingTree.Ignore) + return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, func(name string) error { + return self.c.Git().WorkingTree.Ignore([]string{name}) + }) } func (self *FilesController) exclude(node *filetree.FileNode) error { @@ -1028,7 +1030,9 @@ func (self *FilesController) exclude(node *filetree.FileNode) error { return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr) } - return self.ignoreOrExcludeFile(node, self.c.Tr.ExcludeTracked, self.c.Tr.ExcludeTrackedPrompt, self.c.Tr.Actions.ExcludeFile, self.c.Git().WorkingTree.Exclude) + return self.ignoreOrExcludeFile(node, self.c.Tr.ExcludeTracked, self.c.Tr.ExcludeTrackedPrompt, self.c.Tr.Actions.ExcludeFile, func(name string) error { + return self.c.Git().WorkingTree.Exclude([]string{name}) + }) } func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error {