Skip to content
Open
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
24 changes: 21 additions & 3 deletions taskfile/node_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
giturls "github.com/chainguard-dev/git-urls"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"

Expand Down Expand Up @@ -72,11 +73,28 @@ func (node *GitNode) Read() ([]byte, error) {
return node.ReadContext(context.Background())
}

func (node *GitNode) ReadContext(_ context.Context) ([]byte, error) {
func (node *GitNode) ReadContext(ctx context.Context) ([]byte, error) {
cfg, err := config.LoadConfig(config.GlobalScope)
if err != nil {
return nil, err
}

// Workaround for git.Clone not considering git-config
var longestInsteadOfMatch *config.URL
for _, u := range cfg.URLs {
if strings.HasPrefix(node.url.String(), u.InsteadOf) &&
(longestInsteadOfMatch == nil || len(longestInsteadOfMatch.InsteadOf) < len(u.InsteadOf)) {
longestInsteadOfMatch = u
}
}
// According to spec apply only the longest match
url := longestInsteadOfMatch.ApplyInsteadOf(node.url.String())

fs := memfs.New()
storer := memory.NewStorage()
_, err := git.Clone(storer, fs, &git.CloneOptions{
URL: node.url.String(),

_, err = git.CloneContext(ctx, storer, fs, &git.CloneOptions{
URL: url,
ReferenceName: plumbing.ReferenceName(node.ref),
SingleBranch: true,
Depth: 1,
Expand Down