Add #include directive to .stignore (fixes #424)

Though breaks #502 in a way, as .stignore is not the only place where
stuff gets defined anymore.

Though it never was, as .stignore can be placed in each dir, but I think we
should phase that out in favor of globbing which means that we can then
have a single file, which means that we can have a UI for editing that.

Alternative would be as suggested to include a .stglobalignore which is then synced
as a normal file, but gets included by default.

Then when the UI would have two editors, a local ignore, and a global ignore.
This commit is contained in:
Audrius Butkevicius 2014-08-28 23:45:26 +01:00
parent b0408ef5c6
commit 8c42aea827
2 changed files with 13 additions and 5 deletions

View File

@ -113,10 +113,10 @@ func loadIgnoreFile(ignFile, base string) []*regexp.Regexp {
return nil
}
defer fd.Close()
return parseIgnoreFile(fd, base)
return parseIgnoreFile(fd, base, filepath.Dir(ignFile))
}
func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp {
func parseIgnoreFile(fd io.Reader, base, dir string) []*regexp.Regexp {
var exps []*regexp.Regexp
scanner := bufio.NewScanner(fd)
for scanner.Scan() {
@ -148,6 +148,14 @@ func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp {
continue
}
exps = append(exps, exp)
} else if strings.HasPrefix(line, "#include ") {
includeFile := filepath.Join(dir, strings.Replace(line, "#include ", "", 1))
if _, err := os.Stat(includeFile); os.IsNotExist(err) {
l.Infoln("Could not open ignore include file", includeFile)
} else {
includes := loadIgnoreFile(includeFile, base)
exps = append(exps, includes...)
}
} else {
// Path name or pattern, add it so it matches files both in
// current directory and subdirs.

View File

@ -128,20 +128,20 @@ func TestIgnore(t *testing.T) {
*/other/test
**/deep
`)
patterns := parseIgnoreFile(patStr, "")
patterns := parseIgnoreFile(patStr, "", "")
patStr = bytes.NewBufferString(`
bar
z*
q[abc]x
`)
patterns = append(patterns, parseIgnoreFile(patStr, "foo")...)
patterns = append(patterns, parseIgnoreFile(patStr, "foo", "")...)
patStr = bytes.NewBufferString(`
quux
.*
`)
patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz")...)
patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz", "")...)
var tests = []struct {
f string