From 1f0214adee47d55ee34e27797c945b15a9b5e777 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 18 Jun 2018 19:19:25 -0500 Subject: [PATCH] git/attribs.go: consider system attribute paths --- commands/command_track.go | 1 + git/attribs.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/commands/command_track.go b/commands/command_track.go index 5077c9fb..94a43c08 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -231,6 +231,7 @@ func listPatterns() { func getAllKnownPatterns() []git.AttributePath { knownPatterns := git.GetAttributePaths(cfg.LocalWorkingDir(), cfg.LocalGitDir()) knownPatterns = append(knownPatterns, git.GetRootAttributePaths(cfg.Git)...) + knownPatterns = append(knownPatterns, git.GetSystemAttributePaths(cfg.Os)...) return knownPatterns } diff --git a/git/attribs.go b/git/attribs.go index 0f80e829..6a033b55 100644 --- a/git/attribs.go +++ b/git/attribs.go @@ -47,6 +47,24 @@ func GetRootAttributePaths(cfg Env) []AttributePath { return attrPaths(af, "") } +// GetSystemAttributePaths behaves as GetAttributePaths, and loads information +// only from the system gitattributes file, respecting the $PREFIX environment +// variable. +func GetSystemAttributePaths(env Env) []AttributePath { + prefix, _ := env.Get("PREFIX") + if len(prefix) == 0 { + prefix = string(filepath.Separator) + } + + path := filepath.Join(prefix, "etc", "gitattributes") + + if _, err := os.Stat(path); os.IsNotExist(err) { + return nil + } + + return attrPaths(path, "") +} + // GetAttributePaths returns a list of entries in .gitattributes which are // configured with the filter=lfs attribute // workingDir is the root of the working copy