From 2f92f2ac5f54fec7fe737ad0c4b51e73af837e2f Mon Sep 17 00:00:00 2001 From: Oleg Butuzov Date: Sun, 8 Oct 2023 00:38:14 +0300 Subject: [PATCH] fix: exclude other "ignored" files. (#1356) --- watch.go | 14 ++++++++++++-- watch_test.go | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/watch.go b/watch.go index e390d16c..64bad2f7 100644 --- a/watch.go +++ b/watch.go @@ -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 } diff --git a/watch_test.go b/watch_test.go index 8eb6b850..705caead 100644 --- a/watch_test.go +++ b/watch_test.go @@ -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) + }) + } +}