Skip to content
Open
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
10 changes: 10 additions & 0 deletions taskfile/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ func NewNode(
return node, err
}

func isRemoteEntrypoint(entrypoint string) bool {
scheme, _ := getScheme(entrypoint)
switch scheme {
case "git", "http", "https":
return true
default:
return false
}
}

func getScheme(uri string) (string, error) {
u, err := giturls.Parse(uri)
if u == nil {
Expand Down
6 changes: 1 addition & 5 deletions taskfile/node_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"io"
"os"
"path/filepath"
"strings"

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

func (node *FileNode) ResolveEntrypoint(entrypoint string) (string, error) {
// If the file is remote, we don't need to resolve the path
if strings.Contains(entrypoint, "://") {
return entrypoint, nil
}
if strings.HasPrefix(entrypoint, "git") {
if isRemoteEntrypoint(entrypoint) {
return entrypoint, nil
}

Expand Down
5 changes: 5 additions & 0 deletions taskfile/node_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func (node *GitNode) ReadContext(_ context.Context) ([]byte, error) {
}

func (node *GitNode) ResolveEntrypoint(entrypoint string) (string, error) {
// If the file is remote, we don't need to resolve the path
if isRemoteEntrypoint(entrypoint) {
return entrypoint, nil
}

dir, _ := filepath.Split(node.path)
resolvedEntrypoint := fmt.Sprintf("%s//%s", node.url, filepath.Join(dir, entrypoint))
if node.ref != "" {
Expand Down
11 changes: 11 additions & 0 deletions taskfile/node_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ func TestGitNode_ssh(t *testing.T) {
assert.Equal(t, "ssh://[email protected]/foo/bar.git//common.yml?ref=main", entrypoint)
}

func TestGitNode_sshWithAltRepo(t *testing.T) {
t.Parallel()

node, err := NewGitNode("[email protected]:foo/bar.git//Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)

entrypoint, err := node.ResolveEntrypoint("[email protected]:foo/other.git//Taskfile.yml?ref=dev")
assert.NoError(t, err)
assert.Equal(t, "[email protected]:foo/other.git//Taskfile.yml?ref=dev", entrypoint)
}

func TestGitNode_sshWithDir(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 1 addition & 2 deletions taskfile/node_stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"os"
"strings"

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

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

Expand Down
Loading