github.com/boyter/gocodewalker@v1.3.2/go-gitignore/exclude.go (about) 1 // SPDX-License-Identifier: MIT 2 3 package gitignore 4 5 import ( 6 "os" 7 "path/filepath" 8 ) 9 10 // exclude attempts to return the GitIgnore instance for the 11 // $GIT_DIR/info/exclude from the working copy to which path belongs. 12 func exclude(path string) (GitIgnore, error) { 13 // attempt to locate GIT_DIR 14 _gitdir := os.Getenv("GIT_DIR") 15 if _gitdir == "" { 16 _gitdir = filepath.Join(path, ".git") 17 } 18 _info, _err := os.Stat(_gitdir) 19 if _err != nil { 20 if os.IsNotExist(_err) { 21 return nil, nil 22 } else { 23 return nil, _err 24 } 25 } else if !_info.IsDir() { 26 return nil, nil 27 } 28 29 // is there an info/exclude file within this directory? 30 _file := filepath.Join(_gitdir, "info", "exclude") 31 _, _err = os.Stat(_file) 32 if _err != nil { 33 if os.IsNotExist(_err) { 34 return nil, nil 35 } else { 36 return nil, _err 37 } 38 } 39 40 // attempt to load the exclude file 41 return NewFromFile(_file) 42 } // exclude()