1
0
mirror of https://github.com/go-task/task.git synced 2025-01-20 04:59:37 +02:00

Fix nil errors when merging Taskfiles

Closes #150
This commit is contained in:
Andrey Nering 2018-12-02 14:17:32 -02:00
parent 4ed4ad9852
commit a9b1f38a7c
5 changed files with 39 additions and 0 deletions

View File

@ -20,12 +20,24 @@ func Merge(t1, t2 *Taskfile, namespaces ...string) error {
if t2.Output != "" {
t1.Output = t2.Output
}
if t1.Includes == nil {
t1.Includes = make(map[string]string)
}
for k, v := range t2.Includes {
t1.Includes[k] = v
}
if t1.Vars == nil {
t1.Vars = make(Vars)
}
for k, v := range t2.Vars {
t1.Vars[k] = v
}
if t1.Tasks == nil {
t1.Tasks = make(Tasks)
}
for k, v := range t2.Tasks {
t1.Tasks[taskNameWithNamespace(k, namespaces...)] = v
}

View File

@ -484,3 +484,15 @@ func TestIncludes(t *testing.T) {
}
tt.Run(t)
}
func TestIncludesEmptyMain(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_empty",
Target: "included:default",
TrimSpace: true,
Files: map[string]string{
"file.txt": "default",
},
}
tt.Run(t)
}

1
testdata/includes_empty/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
file.txt

4
testdata/includes_empty/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,4 @@
version: '2'
includes:
included: Taskfile2.yml

10
testdata/includes_empty/Taskfile2.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: '2'
vars:
FILE: file.txt
CONTENT: default
tasks:
default:
cmds:
- echo "{{.CONTENT}}" > {{.FILE}}