git/attribs.go: consider system attribute paths

This commit is contained in:
Taylor Blau 2018-06-18 19:19:25 -05:00
parent b0de5dc883
commit 1f0214adee
2 changed files with 19 additions and 0 deletions

@ -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
}

@ -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