Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/compiler/v3/compiler_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat

var taskRangeFunc func(k string, v taskfile.Var) error
if t != nil {
if strings.HasSuffix(t.Dir, "{{.USER_WORKING_DIR}}") {
t.Dir = "{{.USER_WORKING_DIR}}"
}

// NOTE(@andreynering): We're manually joining these paths here because
// this is the raw task, not the compiled one.
tr := templater.Templater{Vars: result, RemoveNoValue: true}
Expand Down
14 changes: 14 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,20 @@ func TestUserWorkingDirectory(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%s\n", wd), buff.String())
}

func TestUserWorkingDirectoryPwd(t *testing.T) {
var buff bytes.Buffer
e := task.Executor{
Dir: "testdata/user_working_dir_pwd",
Stdout: &buff,
Stderr: &buff,
}
wd, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "included:default"}))
assert.Equal(t, fmt.Sprintf("%s\n", wd), buff.String())
}

func TestPlatforms(t *testing.T) {
var buff bytes.Buffer
e := task.Executor{
Expand Down
5 changes: 5 additions & 0 deletions testdata/user_working_dir_pwd/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'

includes:
included:
taskfile: ./included
8 changes: 8 additions & 0 deletions testdata/user_working_dir_pwd/included/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

tasks:
default:
dir: '{{.USER_WORKING_DIR}}'
cmds:
- pwd
silent: true