@@ -141,6 +141,18 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
141141 if new .Prefix == "" {
142142 new .Prefix = new .Task
143143 }
144+ resolveCmdDir := func (dir string ) (string , error ) {
145+ if dir == "" {
146+ return "" , nil
147+ }
148+
149+ dir , err := execext .ExpandLiteral (dir )
150+ if err != nil {
151+ return "" , err
152+ }
153+
154+ return filepathext .SmartJoin (new .Dir , dir ), nil
155+ }
144156
145157 dotenvEnvs := ast .NewVars ()
146158 if len (new .Dotenv ) > 0 {
@@ -230,7 +242,14 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
230242 newCmd .Cmd = templater .ReplaceWithExtra (cmd .Cmd , cache , extra )
231243 newCmd .Task = templater .ReplaceWithExtra (cmd .Task , cache , extra )
232244 newCmd .If = templater .ReplaceWithExtra (cmd .If , cache , extra )
245+ newCmd .Dir = templater .ReplaceWithExtra (cmd .Dir , cache , extra )
233246 newCmd .Vars = templater .ReplaceVarsWithExtra (cmd .Vars , cache , extra )
247+ if newCmd .Dir != "" {
248+ newCmd .Dir , err = resolveCmdDir (newCmd .Dir )
249+ if err != nil {
250+ return nil , err
251+ }
252+ }
234253 new .Cmds = append (new .Cmds , newCmd )
235254 }
236255 continue
@@ -245,7 +264,14 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
245264 newCmd .Cmd = templater .Replace (cmd .Cmd , cache )
246265 newCmd .Task = templater .Replace (cmd .Task , cache )
247266 newCmd .If = templater .Replace (cmd .If , cache )
267+ newCmd .Dir = templater .Replace (cmd .Dir , cache )
248268 newCmd .Vars = templater .ReplaceVars (cmd .Vars , cache )
269+ if newCmd .Dir != "" {
270+ newCmd .Dir , err = resolveCmdDir (newCmd .Dir )
271+ if err != nil {
272+ return nil , err
273+ }
274+ }
249275 new .Cmds = append (new .Cmds , newCmd )
250276 }
251277 }
0 commit comments