MCPcopy Create free account
hub / github.com/go-task/task / Merge

Method Merge

taskfile/ast/graph.go:48–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func (tfg *TaskfileGraph) Merge() (*Taskfile, error) {
49 hashes, err := graph.TopologicalSort(tfg.Graph)
50 if err != nil {
51 return nil, err
52 }
53
54 predecessorMap, err := tfg.PredecessorMap()
55 if err != nil {
56 return nil, err
57 }
58
59 // Loop over each vertex in reverse topological order except for the root vertex.
60 // This gives us a loop over every included Taskfile in an order which is safe to merge.
61 for i := len(hashes) - 1; i > 0; i-- {
62 hash := hashes[i]
63
64 // Get the included vertex
65 includedVertex, err := tfg.Vertex(hash)
66 if err != nil {
67 return nil, err
68 }
69
70 // Create an error group to wait for all the included Taskfiles to be merged with all its parents
71 var g errgroup.Group
72
73 // Loop over edge that leads to a vertex that includes the current vertex
74 for _, edge := range predecessorMap[hash] {
75
76 // Start a goroutine to process each included Taskfile
77 g.Go(func() error {
78 // Get the base vertex
79 vertex, err := tfg.Vertex(edge.Source)
80 if err != nil {
81 return err
82 }
83
84 // Get the merge options
85 includes, ok := edge.Properties.Data.([]*Include)
86 if !ok {
87 return fmt.Errorf("task: Failed to get merge options")
88 }
89
90 // Merge the included Taskfiles into the parent Taskfile
91 for _, include := range includes {
92 if err := vertex.Taskfile.Merge(
93 includedVertex.Taskfile,
94 include,
95 ); err != nil {
96 return err
97 }
98 }
99
100 return nil
101 })
102 if err := g.Wait(); err != nil {
103 return nil, err
104 }
105 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected