1
0
mirror of https://github.com/go-task/task.git synced 2025-02-09 13:47:06 +02:00

fix: exclude other "ignored" files. (#1356)

This commit is contained in:
Oleg Butuzov 2023-10-08 00:38:14 +03:00 committed by GitHub
parent a70f5aafc2
commit 2f92f2ac5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -176,6 +176,16 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Ca
}
func shouldIgnoreFile(path string) bool {
return strings.Contains(path, "/.git") || strings.Contains(path, "/.hg") ||
strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules")
ignorePaths := []string{
"/.task",
"/.git",
"/.hg",
"/.node_modules",
}
for _, p := range ignorePaths {
if strings.Contains(path, fmt.Sprintf("%s/", p)) || strings.HasSuffix(path, p) {
return true
}
}
return false
}

View File

@ -6,6 +6,7 @@ package task_test
import (
"bytes"
"context"
"fmt"
"os"
"strings"
"testing"
@ -79,3 +80,21 @@ Hello, World!
err = os.RemoveAll(filepathext.SmartJoin(dir, "src"))
require.NoError(t, err)
}
func TestShouldIgnoreFile(t *testing.T) {
tt := []struct {
path string
expect bool
}{
{"/.git/hooks", true},
{"/.github/workflows/build.yaml", false},
}
for k, ct := range tt {
ct := ct
t.Run(fmt.Sprintf("ignore - %d", k), func(t *testing.T) {
t.Parallel()
require.Equal(t, shouldIgnoreFile(ct.path), ct.expect)
})
}
}