mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
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.
This commit is contained in:
parent
a5b4477a20
commit
6dca12131f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue