diff --git a/walk/config.go b/walk/config.go index 45aa00d81..1fe26913d 100644 --- a/walk/config.go +++ b/walk/config.go @@ -24,6 +24,7 @@ import ( "log" "os" "path" + "path/filepath" "strings" "sync" @@ -135,8 +136,12 @@ func (c *Configurer) loadBazelIgnore(repoRoot string, wc *walkConfig) error { log.Printf("the .bazelignore exclusion pattern must not be a glob %s", ignore) continue } - // Ensure we remove trailing slashes or the exclude matching won't work correctly - wc.excludes = append(wc.excludes, strings.TrimSuffix(ignore, "/")) + + // Clean the path to remove any extra '.', './' etc otherwise + // the exclude matching won't work correctly. + ignore = filepath.Clean(ignore) + + wc.excludes = append(wc.excludes, ignore) } return nil } diff --git a/walk/walk_test.go b/walk/walk_test.go index 3dc99d462..7f8d9b84c 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -205,6 +205,10 @@ foo/* # Random comment followed by a line a.file + +# Paths can have a ./ prefix +./b.file +././blah/../ugly/c.file `, }, {Path: ".dot"}, // not ignored @@ -228,6 +232,8 @@ a.file {Path: "dir2/a/b"}, // ignored by .bazelignore 'dir2/a/b' {Path: "dir3/g/h"}, // ignored by .bazelignore 'dir3/' {Path: "a.file"}, // ignored by .bazelignore 'a.file' + {Path: "b.file"}, // ignored by .bazelignore './b.file' + {Path: "ugly/c.file"}, // ignored by .bazelignore './sub/../dir/./c.file' }) defer cleanup()