diff --git a/task_test.go b/task_test.go index a2446bc5eb..30d90a540a 100644 --- a/task_test.go +++ b/task_test.go @@ -1107,6 +1107,30 @@ func TestInternalTask(t *testing.T) { } } +func TestIncludesShadowedDefault(t *testing.T) { + tt := fileContentTest{ + Dir: "testdata/includes_shadowed_default", + Target: "included", + TrimSpace: true, + Files: map[string]string{ + "file.txt": "shadowed", + }, + } + tt.Run(t) +} + +func TestIncludesUnshadowedDefault(t *testing.T) { + tt := fileContentTest{ + Dir: "testdata/includes_unshadowed_default", + Target: "included", + TrimSpace: true, + Files: map[string]string{ + "file.txt": "included", + }, + } + tt.Run(t) +} + func TestSupportedFileNames(t *testing.T) { fileNames := []string{ "Taskfile.yml", diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index d0ee697bd9..fd567916c7 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -153,6 +153,13 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, error) { if err = taskfile.Merge(t, includedTaskfile, &includedTask, namespace); err != nil { return err } + + if includedTaskfile.Tasks["default"] != nil && t.Tasks[namespace] == nil { + defaultTaskName := fmt.Sprintf("%s:default", namespace) + t.Tasks[defaultTaskName].Aliases = append(t.Tasks[defaultTaskName].Aliases, namespace) + t.Tasks[defaultTaskName].Aliases = append(t.Tasks[defaultTaskName].Aliases, includedTask.Aliases...) + } + return nil }) if err != nil { diff --git a/testdata/includes_shadowed_default/Taskfile.yml b/testdata/includes_shadowed_default/Taskfile.yml new file mode 100644 index 0000000000..5588c96212 --- /dev/null +++ b/testdata/includes_shadowed_default/Taskfile.yml @@ -0,0 +1,10 @@ +version: '3' + +includes: + included: + taskfile: Taskfile2.yml + +tasks: + included: + cmds: + - echo "shadowed" > file.txt diff --git a/testdata/includes_shadowed_default/Taskfile2.yml b/testdata/includes_shadowed_default/Taskfile2.yml new file mode 100644 index 0000000000..e944799237 --- /dev/null +++ b/testdata/includes_shadowed_default/Taskfile2.yml @@ -0,0 +1,6 @@ +version: '3' + +tasks: + default: + cmds: + - echo "included" > file.txt diff --git a/testdata/includes_shadowed_default/file.txt b/testdata/includes_shadowed_default/file.txt new file mode 100644 index 0000000000..92a8299c52 --- /dev/null +++ b/testdata/includes_shadowed_default/file.txt @@ -0,0 +1 @@ +shadowed diff --git a/testdata/includes_unshadowed_default/Taskfile.yml b/testdata/includes_unshadowed_default/Taskfile.yml new file mode 100644 index 0000000000..017f9a8b4f --- /dev/null +++ b/testdata/includes_unshadowed_default/Taskfile.yml @@ -0,0 +1,5 @@ +version: '3' + +includes: + included: + taskfile: Taskfile2.yml diff --git a/testdata/includes_unshadowed_default/Taskfile2.yml b/testdata/includes_unshadowed_default/Taskfile2.yml new file mode 100644 index 0000000000..e944799237 --- /dev/null +++ b/testdata/includes_unshadowed_default/Taskfile2.yml @@ -0,0 +1,6 @@ +version: '3' + +tasks: + default: + cmds: + - echo "included" > file.txt diff --git a/testdata/includes_unshadowed_default/file.txt b/testdata/includes_unshadowed_default/file.txt new file mode 100644 index 0000000000..201a102cd7 --- /dev/null +++ b/testdata/includes_unshadowed_default/file.txt @@ -0,0 +1 @@ +included