forked from denormal/go-gitignore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexclude.go
40 lines (36 loc) · 857 Bytes
/
exclude.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gitignore
import (
"os"
"path/filepath"
)
// exclude attempts to return the GitIgnore instance for the
// $GIT_DIR/info/exclude from the working copy to which path belongs.
func exclude(path string) (GitIgnore, error) {
// attempt to locate GIT_DIR
_gitdir := os.Getenv("GIT_DIR")
if _gitdir == "" {
_gitdir = filepath.Join(path, ".git")
}
_info, _err := os.Stat(_gitdir)
if _err != nil {
if os.IsNotExist(_err) {
return nil, nil
} else {
return nil, _err
}
} else if !_info.IsDir() {
return nil, nil
}
// is there an info/exclude file within this directory?
_file := filepath.Join(_gitdir, "info", "exclude")
_, _err = os.Stat(_file)
if _err != nil {
if os.IsNotExist(_err) {
return nil, nil
} else {
return nil, _err
}
}
// attempt to load the exclude file
return NewFromFile(_file)
} // exclude()