mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
feat: support negative globs (#1324)
Co-authored-by: Andrey Nering <andrey@nering.com.br>
This commit is contained in:
@@ -8,16 +8,25 @@ import (
|
||||
|
||||
"github.com/go-task/task/v3/internal/execext"
|
||||
"github.com/go-task/task/v3/internal/filepathext"
|
||||
"github.com/go-task/task/v3/taskfile"
|
||||
)
|
||||
|
||||
func Globs(dir string, globs []string) ([]string, error) {
|
||||
files := make([]string, 0)
|
||||
func Globs(dir string, globs []*taskfile.Glob) ([]string, error) {
|
||||
fileMap := make(map[string]bool)
|
||||
for _, g := range globs {
|
||||
f, err := Glob(dir, g)
|
||||
matches, err := Glob(dir, g.Glob)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
files = append(files, f...)
|
||||
for _, match := range matches {
|
||||
fileMap[match] = !g.Negate
|
||||
}
|
||||
}
|
||||
files := make([]string, 0)
|
||||
for file, includePath := range fileMap {
|
||||
if includePath {
|
||||
files = append(files, file)
|
||||
}
|
||||
}
|
||||
sort.Strings(files)
|
||||
return files, nil
|
||||
|
@@ -53,7 +53,10 @@ func (checker *ChecksumChecker) IsUpToDate(t *taskfile.Task) (bool, error) {
|
||||
if len(t.Generates) > 0 {
|
||||
// For each specified 'generates' field, check whether the files actually exist
|
||||
for _, g := range t.Generates {
|
||||
generates, err := Glob(t.Dir, g)
|
||||
if g.Negate {
|
||||
continue
|
||||
}
|
||||
generates, err := Glob(t.Dir, g.Glob)
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
name: "expect TRUE when no status is defined and sources are up-to-date",
|
||||
task: &taskfile.Task{
|
||||
Status: nil,
|
||||
Sources: []string{"sources"},
|
||||
Sources: []*taskfile.Glob{{Glob: "sources"}},
|
||||
},
|
||||
setupMockStatusChecker: nil,
|
||||
setupMockSourcesChecker: func(m *mocks.SourcesCheckable) {
|
||||
@@ -59,7 +59,7 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
name: "expect FALSE when no status is defined and sources are NOT up-to-date",
|
||||
task: &taskfile.Task{
|
||||
Status: nil,
|
||||
Sources: []string{"sources"},
|
||||
Sources: []*taskfile.Glob{{Glob: "sources"}},
|
||||
},
|
||||
setupMockStatusChecker: nil,
|
||||
setupMockSourcesChecker: func(m *mocks.SourcesCheckable) {
|
||||
@@ -83,7 +83,7 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
name: "expect TRUE when status and sources are up-to-date",
|
||||
task: &taskfile.Task{
|
||||
Status: []string{"status"},
|
||||
Sources: []string{"sources"},
|
||||
Sources: []*taskfile.Glob{{Glob: "sources"}},
|
||||
},
|
||||
setupMockStatusChecker: func(m *mocks.StatusCheckable) {
|
||||
m.EXPECT().IsUpToDate(mock.Anything, mock.Anything).Return(true, nil)
|
||||
@@ -97,7 +97,7 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
name: "expect FALSE when status is up-to-date, but sources are NOT up-to-date",
|
||||
task: &taskfile.Task{
|
||||
Status: []string{"status"},
|
||||
Sources: []string{"sources"},
|
||||
Sources: []*taskfile.Glob{{Glob: "sources"}},
|
||||
},
|
||||
setupMockStatusChecker: func(m *mocks.StatusCheckable) {
|
||||
m.EXPECT().IsUpToDate(mock.Anything, mock.Anything).Return(true, nil)
|
||||
@@ -123,7 +123,7 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
name: "expect FALSE when status is NOT up-to-date, but sources are up-to-date",
|
||||
task: &taskfile.Task{
|
||||
Status: []string{"status"},
|
||||
Sources: []string{"sources"},
|
||||
Sources: []*taskfile.Glob{{Glob: "sources"}},
|
||||
},
|
||||
setupMockStatusChecker: func(m *mocks.StatusCheckable) {
|
||||
m.EXPECT().IsUpToDate(mock.Anything, mock.Anything).Return(false, nil)
|
||||
@@ -137,7 +137,7 @@ func TestIsTaskUpToDate(t *testing.T) {
|
||||
name: "expect FALSE when status and sources are NOT up-to-date",
|
||||
task: &taskfile.Task{
|
||||
Status: []string{"status"},
|
||||
Sources: []string{"sources"},
|
||||
Sources: []*taskfile.Glob{{Glob: "sources"}},
|
||||
},
|
||||
setupMockStatusChecker: func(m *mocks.StatusCheckable) {
|
||||
m.EXPECT().IsUpToDate(mock.Anything, mock.Anything).Return(false, nil)
|
||||
|
Reference in New Issue
Block a user