Skip to content

Commit

Permalink
fix: support leading ./ in .bazelignore
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jun 20, 2024
1 parent 7d10bf7 commit 31c2cb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions walk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"log"
"os"
"path"
"path/filepath"
"strings"
"sync"

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions walk/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit 31c2cb1

Please sign in to comment.