55 "fmt"
66 "strings"
77
8- "github.com/bitrise-io/go-utils/command"
9- "github.com/bitrise-io/go-utils/command/git"
108 "github.com/bitrise-io/go-utils/log"
9+ "github.com/bitrise-io/go-utils/v2/git"
1110)
1211
1312type fetchOptions struct {
@@ -38,7 +37,7 @@ const (
3837 refsHeadsPrefix = "refs/heads/"
3938)
4039
41- func fetch (gitCmd git.Git , remote string , ref string , options fetchOptions ) error {
40+ func fetch (gitFactory git.Factory , remote string , ref string , options fetchOptions ) error {
4241 var opts []string
4342 opts = append (opts , jobsFlag )
4443
@@ -67,11 +66,11 @@ func fetch(gitCmd git.Git, remote string, ref string, options fetchOptions) erro
6766 branch = strings .TrimPrefix (ref , refsHeadsPrefix )
6867 }
6968
70- if err := runner .RunWithRetry (func () * command. Model {
71- return gitCmd .Fetch (opts ... )
69+ if err := runner .RunWithRetry (func () git. Template {
70+ return gitFactory .Fetch (opts ... )
7271 }); err != nil {
7372 return handleCheckoutError (
74- listBranches (gitCmd ),
73+ listBranches (gitFactory ),
7574 fetchFailedTag ,
7675 err ,
7776 "Fetching repository has failed" ,
@@ -82,15 +81,15 @@ func fetch(gitCmd git.Git, remote string, ref string, options fetchOptions) erro
8281 return nil
8382}
8483
85- func checkoutWithCustomRetry (gitCmd git.Git , arg string , retry fallbackRetry ) error {
86- if cErr := runner .Run (gitCmd .Checkout (arg )); cErr != nil {
84+ func checkoutWithCustomRetry (gitFactory git.Factory , arg string , retry fallbackRetry ) error {
85+ if cErr := runner .Run (gitFactory .Checkout (arg )); cErr != nil {
8786 if retry != nil {
8887 log .Warnf ("Checkout failed (%s): %v" , arg , cErr )
89- if err := retry .do (gitCmd ); err != nil {
88+ if err := retry .do (gitFactory ); err != nil {
9089 return err
9190 }
9291
93- return runner .Run (gitCmd .Checkout (arg ))
92+ return runner .Run (gitFactory .Checkout (arg ))
9493 }
9594
9695 return fmt .Errorf ("checkout failed (%s): %w" , arg , cErr )
@@ -99,21 +98,21 @@ func checkoutWithCustomRetry(gitCmd git.Git, arg string, retry fallbackRetry) er
9998 return nil
10099}
101100
102- func forceCheckoutRemoteBranch (gitCmd git.Git , remote string , branchRef string , fetchTraits fetchOptions ) error {
101+ func forceCheckoutRemoteBranch (gitFactory git.Factory , remote string , branchRef string , fetchTraits fetchOptions ) error {
103102 branch := strings .TrimPrefix (branchRef , refsHeadsPrefix )
104- if err := fetch (gitCmd , remote , branchRef , fetchTraits ); err != nil {
103+ if err := fetch (gitFactory , remote , branchRef , fetchTraits ); err != nil {
105104 wErr := fmt .Errorf ("fetch branch %s: %w" , branchRef , err )
106105 return fmt .Errorf ("%v: %w" , wErr , errors .New ("please make sure the branch still exists" ))
107106 }
108-
107+
109108 remoteBranch := fmt .Sprintf ("%s/%s" , remote , branch )
110109 // -B: create the branch if it doesn't exist, reset if it does
111110 // The latter is important in persistent environments because shallow-fetching only fetches 1 commit,
112111 // so the next run would see unrelated histories after shallow-fetching another single commit.
113- err := runner .Run (gitCmd .Checkout ("-B" , branch , remoteBranch ))
112+ err := runner .Run (gitFactory .Checkout ("-B" , branch , remoteBranch ))
114113 if err != nil {
115114 return handleCheckoutError (
116- listBranches (gitCmd ),
115+ listBranches (gitFactory ),
117116 checkoutFailedTag ,
118117 err ,
119118 "Checkout has failed" ,
@@ -124,15 +123,15 @@ func forceCheckoutRemoteBranch(gitCmd git.Git, remote string, branchRef string,
124123 return nil
125124}
126125
127- func mergeWithCustomRetry (gitCmd git.Git , arg string , retry fallbackRetry ) error {
128- if mErr := runner .Run (gitCmd .Merge (arg )); mErr != nil {
126+ func mergeWithCustomRetry (gitFactory git.Factory , arg string , retry fallbackRetry ) error {
127+ if mErr := runner .Run (gitFactory .Merge (arg )); mErr != nil {
129128 if retry != nil {
130129 log .Warnf ("Merge failed (%s): %v" , arg , mErr )
131- if err := retry .do (gitCmd ); err != nil {
130+ if err := retry .do (gitFactory ); err != nil {
132131 return err
133132 }
134133
135- return runner .Run (gitCmd .Merge (arg ))
134+ return runner .Run (gitFactory .Merge (arg ))
136135 }
137136
138137 wErr := fmt .Errorf ("merge failed (%s): %w" , arg , mErr )
@@ -142,8 +141,8 @@ func mergeWithCustomRetry(gitCmd git.Git, arg string, retry fallbackRetry) error
142141 return nil
143142}
144143
145- func detachHead (gitCmd git.Git ) error {
146- if err := runner .Run (gitCmd .Checkout ("--detach" )); err != nil {
144+ func detachHead (gitFactory git.Factory ) error {
145+ if err := runner .Run (gitFactory .Checkout ("--detach" )); err != nil {
147146 return newStepError (
148147 "detach_head_failed" ,
149148 fmt .Errorf ("detaching head failed: %w" , err ),
@@ -154,6 +153,6 @@ func detachHead(gitCmd git.Git) error {
154153 return nil
155154}
156155
157- func deleteRef (gitCmd git.Git , ref string ) error {
158- return runner .Run (gitCmd .UpdateRef ("-d" , ref ))
156+ func deleteRef (gitFactory git.Factory , ref string ) error {
157+ return runner .Run (gitFactory .UpdateRef ("-d" , ref ))
159158}
0 commit comments