lib/ignores: Fix ignore loading, report errors to UI (fixes #4901) (#4932)

This commit is contained in:
Audrius Butkevicius
2018-05-08 22:37:13 +01:00
committed by Jakob Borg
parent 2343c82c33
commit a48a31e3f5
3 changed files with 54 additions and 5 deletions

View File

@@ -981,3 +981,42 @@ func TestIssue4689(t *testing.T) {
t.Fatalf("wrong lines parsing changed comment:\n%v", lines)
}
}
func TestIssue4901(t *testing.T) {
dir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
stignore := `
#include unicorn-lazor-death
puppy
`
if err := ioutil.WriteFile(filepath.Join(dir, ".stignore"), []byte(stignore), 0777); err != nil {
t.Fatalf(err.Error())
}
pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, dir), WithCache(true))
// Cache does not suddenly make the load succeed.
for i := 0; i < 2; i++ {
err := pats.Load(".stignore")
if err == nil {
t.Fatalf("expected an error")
}
if fs.IsNotExist(err) {
t.Fatalf("unexpected error type")
}
}
if err := ioutil.WriteFile(filepath.Join(dir, "unicorn-lazor-death"), []byte(" "), 0777); err != nil {
t.Fatalf(err.Error())
}
err = pats.Load(".stignore")
if err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
}