Skip to content

Commit

Permalink
Merge pull request #83 from dbaggerman/issue-82
Browse files Browse the repository at this point in the history
fix ignoring .git on absolute paths
  • Loading branch information
boyter committed Jun 20, 2019
2 parents eb9dd34 + c301925 commit 36667db
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions processor/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func walkDirectoryParallel(root string, output chan *FileJob) {
// Need to check if the directory is in the blacklist and if so don't bother adding a goroutine to process it
shouldSkip := false
for _, black := range PathBlacklist {
if strings.HasPrefix(filepath.Join(root, f.Name()), black) {
if strings.HasPrefix(filepath.Join(root, f.Name()), filepath.Join(root, black)) {
shouldSkip = true
if Verbose {
printWarn(fmt.Sprintf("skipping directory due to being in blacklist: %s", filepath.Join(root, f.Name())))
Expand Down Expand Up @@ -267,7 +267,7 @@ func walkDirectory(toWalk string, blackList []string, extensionLookup map[string

if info.IsDir() {
for _, black := range blackList {
if strings.HasPrefix(root, black+"/") || strings.HasPrefix(root, black) {
if strings.HasPrefix(root, filepath.Join(toWalk, black)) {
if Verbose {
printWarn(fmt.Sprintf("skipping directory due to being in blacklist: %s", root))
}
Expand Down
40 changes: 40 additions & 0 deletions processor/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package processor

import (
"math/rand"
"path/filepath"
"testing"
"strings"
)

func TestGetExtension(t *testing.T) {
Expand Down Expand Up @@ -147,6 +149,44 @@ func TestWalkDirectoryParallelIgnoresRootTrailingSlash(t *testing.T) {
}
}

// Issue #82 - project .git directory not being filtered when using absolute
// path argument
func TestWalkDirectoryParallelIgnoresAbsoluteGitPath(t *testing.T) {
isLazy = false
ProcessConstants()

// master is a file extension for ASP.NET, and also a filename (almost)
// certain to appear in the .git directory.
// This test also relies on the behaviour of treating `master` as a file
// with the `master` file extension.
WhiteListExtensions = []string{"master", "go"}
Exclude = []string{"vendor"}
PathBlacklist = []string{".git", "vendor"}
Verbose = true
Trace = true
Debug = true
GcFileCount = 10

inputChan := make(chan *FileJob, 10000)
absBaseDir, _ := filepath.Abs("../")
absGitDir := filepath.Join(absBaseDir, ".git")

walkDirectoryParallel(absBaseDir, inputChan)
close(inputChan)

sawGit := false
for fileJob := range inputChan {
if strings.HasPrefix(fileJob.Location, absGitDir) {
sawGit = true
break
}
}

if sawGit {
t.Errorf("Expected .git folder to be ignored")
}
}

func TestWalkDirectory(t *testing.T) {
Debug = true
Exclude = []string{"test"}
Expand Down

0 comments on commit 36667db

Please sign in to comment.