Skip to content

Commit 348158a

Browse files
authored
fix: properly resolve remote entrypoints (#2438)
1 parent c3e410e commit 348158a

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

taskfile/node.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ func NewNode(
7272
return node, err
7373
}
7474

75+
func isRemoteEntrypoint(entrypoint string) bool {
76+
scheme, _ := getScheme(entrypoint)
77+
switch scheme {
78+
case "git", "http", "https":
79+
return true
80+
default:
81+
return false
82+
}
83+
}
84+
7585
func getScheme(uri string) (string, error) {
7686
u, err := giturls.Parse(uri)
7787
if u == nil {

taskfile/node_file.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"io"
55
"os"
66
"path/filepath"
7-
"strings"
87

98
"github.com/go-task/task/v3/internal/execext"
109
"github.com/go-task/task/v3/internal/filepathext"
@@ -51,10 +50,7 @@ func (node *FileNode) Read() ([]byte, error) {
5150

5251
func (node *FileNode) ResolveEntrypoint(entrypoint string) (string, error) {
5352
// If the file is remote, we don't need to resolve the path
54-
if strings.Contains(entrypoint, "://") {
55-
return entrypoint, nil
56-
}
57-
if strings.HasPrefix(entrypoint, "git") {
53+
if isRemoteEntrypoint(entrypoint) {
5854
return entrypoint, nil
5955
}
6056

taskfile/node_git.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func (node *GitNode) ReadContext(_ context.Context) ([]byte, error) {
9898
}
9999

100100
func (node *GitNode) ResolveEntrypoint(entrypoint string) (string, error) {
101+
// If the file is remote, we don't need to resolve the path
102+
if isRemoteEntrypoint(entrypoint) {
103+
return entrypoint, nil
104+
}
105+
101106
dir, _ := filepath.Split(node.path)
102107
resolvedEntrypoint := fmt.Sprintf("%s//%s", node.url, filepath.Join(dir, entrypoint))
103108
if node.ref != "" {

taskfile/node_git_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ func TestGitNode_ssh(t *testing.T) {
2121
assert.Equal(t, "ssh://[email protected]/foo/bar.git//common.yml?ref=main", entrypoint)
2222
}
2323

24+
func TestGitNode_sshWithAltRepo(t *testing.T) {
25+
t.Parallel()
26+
27+
node, err := NewGitNode("[email protected]:foo/bar.git//Taskfile.yml?ref=main", "", false)
28+
assert.NoError(t, err)
29+
30+
entrypoint, err := node.ResolveEntrypoint("[email protected]:foo/other.git//Taskfile.yml?ref=dev")
31+
assert.NoError(t, err)
32+
assert.Equal(t, "[email protected]:foo/other.git//Taskfile.yml?ref=dev", entrypoint)
33+
}
34+
2435
func TestGitNode_sshWithDir(t *testing.T) {
2536
t.Parallel()
2637

taskfile/node_stdin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bufio"
55
"fmt"
66
"os"
7-
"strings"
87

98
"github.com/go-task/task/v3/internal/execext"
109
"github.com/go-task/task/v3/internal/filepathext"
@@ -43,7 +42,7 @@ func (node *StdinNode) Read() ([]byte, error) {
4342

4443
func (node *StdinNode) ResolveEntrypoint(entrypoint string) (string, error) {
4544
// If the file is remote, we don't need to resolve the path
46-
if strings.Contains(entrypoint, "://") {
45+
if isRemoteEntrypoint(entrypoint) {
4746
return entrypoint, nil
4847
}
4948

0 commit comments

Comments
 (0)