From dd565208e236bc56230e75bedcc5082d171e6155 Mon Sep 17 00:00:00 2001 From: Michael Goodness Date: Fri, 6 May 2022 17:13:35 -0500 Subject: [PATCH] fix(git): add auth to fetch (#8664) Signed-off-by: Michael Goodness --- workflow/artifacts/git/git.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/workflow/artifacts/git/git.go b/workflow/artifacts/git/git.go index 144fc695d2f8..b0e590afeb3f 100644 --- a/workflow/artifacts/git/git.go +++ b/workflow/artifacts/git/git.go @@ -148,12 +148,16 @@ func (g *ArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string) error { } if a.Revision != "" { - refspecs := []config.RefSpec{"refs/heads/*:refs/heads/*"} + refSpecs := []config.RefSpec{"refs/heads/*:refs/heads/*"} if a.SingleBranch { - refspecs = []config.RefSpec{config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%s", a.Branch, a.Branch))} + refSpecs = []config.RefSpec{config.RefSpec(fmt.Sprintf("refs/heads/%s:refs/heads/%s", a.Branch, a.Branch))} } - if err := r.Fetch(&git.FetchOptions{RefSpecs: refspecs}); isFetchErr(err) { - return fmt.Errorf("failed to fatch refs: %w", err) + opts := &git.FetchOptions{Auth: auth, RefSpecs: refSpecs} + if err := opts.Validate(); err != nil { + return fmt.Errorf("failed to validate fetch %v: %w", refSpecs, err) + } + if err := r.Fetch(opts); isFetchErr(err) { + return fmt.Errorf("failed to fetch %v: %w", refSpecs, err) } h, err := r.ResolveRevision(plumbing.Revision(a.Revision)) if err != nil {