From 5c8a387cd452593f2655cbdb6d0ace78c7043c3d Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Sat, 15 Nov 2025 16:19:09 +0100 Subject: [PATCH] fix --- https.yml | 15 +++++++++++++++ internal/flags/flags.go | 2 +- taskfile/node_git.go | 16 ++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 https.yml diff --git a/https.yml b/https.yml new file mode 100644 index 00000000..e70ee2f3 --- /dev/null +++ b/https.yml @@ -0,0 +1,15 @@ +# https://taskfile.dev + +version: '3' +includes: + app: + taskfile: https://github.com/pbstck/taskfiles.git//taskfile/rust.yml?ref=main + +vars: + GREETING: Hello, World! + +tasks: + default: + cmds: + - echo "{{.GREETING}}" + silent: true diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 5787e17a..5b874f6b 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -152,7 +152,7 @@ func init() { if experiments.RemoteTaskfiles.Enabled() { pflag.BoolVar(&Download, "download", false, "Downloads a cached version of a remote Taskfile.") pflag.BoolVar(&Offline, "offline", getConfig(config, func() *bool { return config.Remote.Offline }, false), "Forces Task to only use local or cached Taskfiles.") - pflag.DurationVar(&Timeout, "timeout", getConfig(config, func() *time.Duration { return config.Remote.Timeout }, time.Second*10), "Timeout for downloading remote Taskfiles.") + pflag.DurationVar(&Timeout, "timeout", getConfig(config, func() *time.Duration { return config.Remote.Timeout }, time.Minute*10), "Timeout for downloading remote Taskfiles.") pflag.BoolVar(&ClearCache, "clear-cache", false, "Clear the remote cache.") pflag.DurationVar(&CacheExpiryDuration, "expiry", getConfig(config, func() *time.Duration { return config.Remote.CacheExpiry }, 0), "Expiry duration for cached remote Taskfiles.") } diff --git a/taskfile/node_git.go b/taskfile/node_git.go index eafd382e..883b7480 100644 --- a/taskfile/node_git.go +++ b/taskfile/node_git.go @@ -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"