From 16ac79c56178dec036ce2708b88ae9aa5c75f491 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Tue, 7 Jan 2025 21:05:43 +0100 Subject: [PATCH] merge preconditions --- taskfile/ast/precondition.go | 14 ++++++++++++++ taskfile/ast/taskfile.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/taskfile/ast/precondition.go b/taskfile/ast/precondition.go index 9d8ad80f..69ca5f00 100644 --- a/taskfile/ast/precondition.go +++ b/taskfile/ast/precondition.go @@ -40,6 +40,20 @@ func (p *Preconditions) DeepCopy() *Preconditions { } } +func (p *Preconditions) Merge(other *Preconditions) { + if p == nil || p.Preconditions == nil || other == nil { + return + } + + p.mutex.Lock() + defer p.mutex.Unlock() + + other.mutex.RLock() + defer other.mutex.RUnlock() + + p.Preconditions = append(p.Preconditions, deepcopy.Slice(other.Preconditions)...) +} + func (p *Precondition) DeepCopy() *Precondition { if p == nil { return nil diff --git a/taskfile/ast/taskfile.go b/taskfile/ast/taskfile.go index 98e2fce3..988ae216 100644 --- a/taskfile/ast/taskfile.go +++ b/taskfile/ast/taskfile.go @@ -65,7 +65,7 @@ func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error { } t1.Vars.Merge(t2.Vars, include) t1.Env.Merge(t2.Env, include) - // TODO:@vmaerten Merge precondition + t1.Preconditions.Merge(t2.Preconditions) return t1.Tasks.Merge(t2.Tasks, include, t1.Vars) }