@@ -15,6 +15,7 @@ import (
1515 "github.com/go-task/task/v3/errors"
1616 "github.com/go-task/task/v3/internal/execext"
1717 "github.com/go-task/task/v3/internal/filepathext"
18+ "github.com/go-task/task/v3/internal/fsext"
1819)
1920
2021// An GitNode is a node that reads a Taskfile from a remote location via Git.
@@ -104,13 +105,13 @@ func (node *GitNode) buildURL() string {
104105 // Get the base URL
105106 baseURL := node .url .String ()
106107
107- ref := node .ref
108- if ref == "" {
109- ref = "HEAD"
110- }
111108 // Always use git:: prefix for git URLs (following Terraform's pattern)
112109 // This forces go-getter to use git protocol
113- return fmt .Sprintf ("git::%s?ref=%s&depth=1" , baseURL , ref )
110+ if node .ref != "" {
111+ return fmt .Sprintf ("git::%s?ref=%s&depth=1" , baseURL , node .ref )
112+ }
113+ // When no ref is specified, omit it entirely to let git clone the default branch
114+ return fmt .Sprintf ("git::%s?depth=1" , baseURL )
114115}
115116
116117// getOrCloneRepo returns the path to a cached git repository.
@@ -164,11 +165,16 @@ func (node *GitNode) ReadContext(ctx context.Context) ([]byte, error) {
164165 }
165166
166167 // Build path to Taskfile in the cached repo
167- taskfilePath := node .path
168- if taskfilePath == "" {
169- taskfilePath = "Taskfile.yml"
168+ // If node.path is empty, search in repo root; otherwise search in the specified path
169+ // fsext.SearchPath handles both files and directories (searching for DefaultTaskfiles)
170+ searchPath := repoDir
171+ if node .path != "" {
172+ searchPath = filepath .Join (repoDir , node .path )
173+ }
174+ filePath , err := fsext .SearchPath (searchPath , DefaultTaskfiles )
175+ if err != nil {
176+ return nil , err
170177 }
171- filePath := filepath .Join (repoDir , taskfilePath )
172178
173179 // Read file from cached repo
174180 b , err := os .ReadFile (filePath )
@@ -230,7 +236,7 @@ func (node *GitNode) repoCacheKey() string {
230236
231237 ref := node .ref
232238 if ref == "" {
233- ref = "HEAD"
239+ ref = "_default_" // Placeholder for the remote's default branch
234240 }
235241
236242 return filepath .Join (node .url .Host , repoPath , ref )
0 commit comments