11package git
22
33import (
4+ "fmt"
45 "net/http"
56 "net/url"
67 "os"
@@ -9,7 +10,6 @@ import (
910 "strings"
1011
1112 "github.com/moby/sys/symlink"
12- "github.com/pkg/errors"
1313)
1414
1515type gitRepo struct {
@@ -61,17 +61,17 @@ func (repo gitRepo) clone() (checkoutDir string, retErr error) {
6161 }()
6262
6363 if out , err := repo .gitWithinDir (root , "init" ); err != nil {
64- return "" , errors . Wrapf ( err , "failed to init repo at %s: %s" , root , out )
64+ return "" , fmt . Errorf ( "failed to init repo at %s: %s: %w " , root , out , err )
6565 }
6666
6767 // Add origin remote for compatibility with previous implementation that
6868 // used "git clone" and also to make sure local refs are created for branches
6969 if out , err := repo .gitWithinDir (root , "remote" , "add" , "origin" , repo .remote ); err != nil {
70- return "" , errors . Wrapf ( err , "failed add origin repo at %s: %s" , repo .remote , out )
70+ return "" , fmt . Errorf ( "failed add origin repo at %s: %s: %w " , repo .remote , out , err )
7171 }
7272
7373 if output , err := repo .gitWithinDir (root , fetch ... ); err != nil {
74- return "" , errors . Wrapf ( err , "error fetching: %s" , output )
74+ return "" , fmt . Errorf ( "error fetching: %s: %w " , output , err )
7575 }
7676
7777 checkoutDir , err = repo .checkout (root )
@@ -83,7 +83,7 @@ func (repo gitRepo) clone() (checkoutDir string, retErr error) {
8383 cmd .Dir = root
8484 output , err := cmd .CombinedOutput ()
8585 if err != nil {
86- return "" , errors . Wrapf ( err , "error initializing submodules: %s" , output )
86+ return "" , fmt . Errorf ( "error initializing submodules: %s: %w " , output , err )
8787 }
8888
8989 return checkoutDir , nil
@@ -113,7 +113,7 @@ func parseRemoteURL(remoteURL string) (gitRepo, error) {
113113 }
114114
115115 if strings .HasPrefix (repo .ref , "-" ) {
116- return gitRepo {}, errors .Errorf ("invalid refspec: %s" , repo .ref )
116+ return gitRepo {}, fmt .Errorf ("invalid refspec: %s" , repo .ref )
117117 }
118118
119119 return repo , nil
@@ -178,22 +178,22 @@ func (repo gitRepo) checkout(root string) (string, error) {
178178 if output , err := repo .gitWithinDir (root , "checkout" , repo .ref ); err != nil {
179179 // If checking out by branch name fails check out the last fetched ref
180180 if _ , err2 := repo .gitWithinDir (root , "checkout" , "FETCH_HEAD" ); err2 != nil {
181- return "" , errors . Wrapf ( err , "error checking out %s: %s" , repo .ref , output )
181+ return "" , fmt . Errorf ( "error checking out %s: %s: %w " , repo .ref , output , err )
182182 }
183183 }
184184
185185 if repo .subdir != "" {
186186 newCtx , err := symlink .FollowSymlinkInScope (filepath .Join (root , repo .subdir ), root )
187187 if err != nil {
188- return "" , errors . Wrapf ( err , "error setting git context, %q not within git root" , repo .subdir )
188+ return "" , fmt . Errorf ( "error setting git context, %q not within git root: %w " , repo .subdir , err )
189189 }
190190
191191 fi , err := os .Stat (newCtx )
192192 if err != nil {
193193 return "" , err
194194 }
195195 if ! fi .IsDir () {
196- return "" , errors .Errorf ("error setting git context, not a directory: %s" , newCtx )
196+ return "" , fmt .Errorf ("error setting git context, not a directory: %s" , newCtx )
197197 }
198198 root = newCtx
199199 }
0 commit comments