diff --git a/git.go b/git.go index c7e52d0..a9b4c1a 100644 --- a/git.go +++ b/git.go @@ -1,12 +1,13 @@ package getit import ( - "bytes" "context" "fmt" "net/url" "os/exec" "strings" + + "github.com/kballard/go-shellquote" ) // The Git [Resolver] uses Git repositories as archive sources, cloning directly. @@ -43,11 +44,10 @@ func (g *Git) Fetch(ctx context.Context, source Source, dest string) error { repoURL := convertGitURL(source.URL) args = append(args, repoURL, dest) - stderr := &bytes.Buffer{} cmd := exec.CommandContext(ctx, "git", args...) - cmd.Stderr = stderr - if err := cmd.Run(); err != nil { - return fmt.Errorf("git clone failed: %w: %s", err, stderr) + if output, err := cmd.CombinedOutput(); err != nil { + argsStr := shellquote.Join(args...) + return fmt.Errorf("git clone failed: git %s: %w: %s", argsStr, err, output) } return nil } diff --git a/go.mod b/go.mod index 5ed5d25..e4c9326 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,5 @@ require github.com/alecthomas/assert/v2 v2.11.0 require ( github.com/alecthomas/repr v0.4.0 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 ) diff --git a/go.sum b/go.sum index f571a34..f3f3083 100644 --- a/go.sum +++ b/go.sum @@ -4,3 +4,5 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=