1
0
mirror of https://github.com/go-task/task.git synced 2025-11-27 22:38:20 +02:00
This commit is contained in:
Valentin Maerten
2025-11-15 16:19:09 +01:00
parent f53ad3f36a
commit 5c8a387cd4
3 changed files with 26 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
giturls "github.com/chainguard-dev/git-urls"
"github.com/hashicorp/go-getter"
@@ -83,11 +84,15 @@ func (node *GitNode) buildURL() string {
}
func (node *GitNode) ReadContext(ctx context.Context) ([]byte, error) {
// Create temporary directory for git clone
tmpDir, err := os.MkdirTemp("", "task-git-*")
if err != nil {
return nil, fmt.Errorf("failed to create temp dir: %w", err)
}
return node.readWithGoGetter(ctx)
}
func (node *GitNode) readWithGoGetter(ctx context.Context) ([]byte, error) {
// IMPORTANT: Do NOT create tmpDir in advance!
// If the directory exists, go-getter will use update() instead of clone()
// which is 3x slower (git init + fetch --tags + pull instead of a simple clone)
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("task-git-getter-%d", time.Now().UnixNano()))
defer func() {
_ = os.RemoveAll(tmpDir)
}()
@@ -107,7 +112,6 @@ func (node *GitNode) ReadContext(ctx context.Context) ([]byte, error) {
}
// Build path to Taskfile in tmpdir
// If no path specified, use default Taskfile.yml
taskfilePath := node.path
if taskfilePath == "" {
taskfilePath = "Taskfile.yml"