Skip to content

Commit a9b1f38

Browse files
committed
Fix nil errors when merging Taskfiles
Closes #150
1 parent 4ed4ad9 commit a9b1f38

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

internal/taskfile/merge.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ func Merge(t1, t2 *Taskfile, namespaces ...string) error {
2020
if t2.Output != "" {
2121
t1.Output = t2.Output
2222
}
23+
24+
if t1.Includes == nil {
25+
t1.Includes = make(map[string]string)
26+
}
2327
for k, v := range t2.Includes {
2428
t1.Includes[k] = v
2529
}
30+
31+
if t1.Vars == nil {
32+
t1.Vars = make(Vars)
33+
}
2634
for k, v := range t2.Vars {
2735
t1.Vars[k] = v
2836
}
37+
38+
if t1.Tasks == nil {
39+
t1.Tasks = make(Tasks)
40+
}
2941
for k, v := range t2.Tasks {
3042
t1.Tasks[taskNameWithNamespace(k, namespaces...)] = v
3143
}

task_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,15 @@ func TestIncludes(t *testing.T) {
484484
}
485485
tt.Run(t)
486486
}
487+
488+
func TestIncludesEmptyMain(t *testing.T) {
489+
tt := fileContentTest{
490+
Dir: "testdata/includes_empty",
491+
Target: "included:default",
492+
TrimSpace: true,
493+
Files: map[string]string{
494+
"file.txt": "default",
495+
},
496+
}
497+
tt.Run(t)
498+
}

testdata/includes_empty/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file.txt
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: '2'
2+
3+
includes:
4+
included: Taskfile2.yml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '2'
2+
3+
vars:
4+
FILE: file.txt
5+
CONTENT: default
6+
7+
tasks:
8+
default:
9+
cmds:
10+
- echo "{{.CONTENT}}" > {{.FILE}}

0 commit comments

Comments
 (0)