@@ -47,18 +47,25 @@ func (g *gitService) CloneRepository(repoURL, clonePath, branch string, createNe
47
47
if createNewBranch {
48
48
// Clone the default branch first, then create new branch
49
49
cmd = exec .Command ("git" , "clone" , "--depth" , "50" , repoURL , clonePath )
50
+ log .Infof ("Executing Git command: %s" , cmd .String ())
50
51
} else {
51
52
// Try to clone specific branch directly
52
53
cmd = exec .Command ("git" , "clone" , "--depth" , "50" , "--branch" , branch , repoURL , clonePath )
54
+ log .Infof ("Executing Git command: %s" , cmd .String ())
53
55
}
54
56
55
57
output , err := cmd .CombinedOutput ()
56
58
if err != nil {
59
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
57
60
if ! createNewBranch {
58
61
// If direct branch clone failed, try cloning default branch first
59
62
log .Warnf ("Failed to clone specific branch %s directly, cloning default branch: %v" , branch , err )
60
63
cmd = exec .Command ("git" , "clone" , "--depth" , "50" , repoURL , clonePath )
64
+ log .Infof ("Executing fallback Git command: %s" , cmd .String ())
61
65
output , err = cmd .CombinedOutput ()
66
+ if err != nil {
67
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
68
+ }
62
69
}
63
70
if err != nil {
64
71
return GitError ("clone" , clonePath , fmt .Errorf ("%s: %w" , string (output ), err ))
@@ -104,8 +111,10 @@ func (g *gitService) CloneRepository(repoURL, clonePath, branch string, createNe
104
111
func (g * gitService ) GetRemoteURL (repoPath string ) (string , error ) {
105
112
cmd := exec .Command ("git" , "remote" , "get-url" , "origin" )
106
113
cmd .Dir = repoPath
114
+ log .Infof ("Executing Git command: %s" , cmd .String ())
107
115
output , err := cmd .Output ()
108
116
if err != nil {
117
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
109
118
return "" , GitError ("get_remote_url" , repoPath , err )
110
119
}
111
120
return strings .TrimSpace (string (output )), nil
@@ -115,8 +124,10 @@ func (g *gitService) GetRemoteURL(repoPath string) (string, error) {
115
124
func (g * gitService ) GetCurrentBranch (repoPath string ) (string , error ) {
116
125
cmd := exec .Command ("git" , "rev-parse" , "--abbrev-ref" , "HEAD" )
117
126
cmd .Dir = repoPath
127
+ log .Infof ("Executing Git command: %s" , cmd .String ())
118
128
output , err := cmd .Output ()
119
129
if err != nil {
130
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
120
131
return "" , GitError ("get_current_branch" , repoPath , err )
121
132
}
122
133
return strings .TrimSpace (string (output )), nil
@@ -126,8 +137,10 @@ func (g *gitService) GetCurrentBranch(repoPath string) (string, error) {
126
137
func (g * gitService ) GetCurrentCommit (repoPath string ) (string , error ) {
127
138
cmd := exec .Command ("git" , "rev-parse" , "HEAD" )
128
139
cmd .Dir = repoPath
140
+ log .Infof ("Executing Git command: %s" , cmd .String ())
129
141
output , err := cmd .Output ()
130
142
if err != nil {
143
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
131
144
return "" , fmt .Errorf ("failed to get current commit: %w" , err )
132
145
}
133
146
return strings .TrimSpace (string (output )), nil
@@ -137,8 +150,10 @@ func (g *gitService) GetCurrentCommit(repoPath string) (string, error) {
137
150
func (g * gitService ) GetBranchCommit (repoPath , branch string ) (string , error ) {
138
151
cmd := exec .Command ("git" , "rev-parse" , fmt .Sprintf ("origin/%s" , branch ))
139
152
cmd .Dir = repoPath
153
+ log .Infof ("Executing Git command: %s" , cmd .String ())
140
154
output , err := cmd .Output ()
141
155
if err != nil {
156
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
142
157
return "" , fmt .Errorf ("failed to get branch commit for %s: %w" , branch , err )
143
158
}
144
159
return strings .TrimSpace (string (output )), nil
@@ -184,7 +199,9 @@ func (g *gitService) ValidateBranch(repoPath, expectedBranch string) bool {
184
199
func (g * gitService ) ConfigureSafeDirectory (repoPath string ) error {
185
200
cmd := exec .Command ("git" , "config" , "--local" , "--add" , "safe.directory" , repoPath )
186
201
cmd .Dir = repoPath
202
+ log .Infof ("Executing Git command: %s" , cmd .String ())
187
203
if output , err := cmd .CombinedOutput (); err != nil {
204
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
188
205
return GitError ("config_safe_directory" , repoPath , fmt .Errorf ("%s: %w" , string (output ), err ))
189
206
}
190
207
return nil
@@ -194,7 +211,9 @@ func (g *gitService) ConfigureSafeDirectory(repoPath string) error {
194
211
func (g * gitService ) ConfigurePullStrategy (repoPath string ) error {
195
212
cmd := exec .Command ("git" , "config" , "--local" , "pull.rebase" , "true" )
196
213
cmd .Dir = repoPath
214
+ log .Infof ("Executing Git command: %s" , cmd .String ())
197
215
if output , err := cmd .CombinedOutput (); err != nil {
216
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
198
217
return fmt .Errorf ("failed to configure pull strategy: %w, output: %s" , err , string (output ))
199
218
}
200
219
return nil
@@ -204,7 +223,9 @@ func (g *gitService) ConfigurePullStrategy(repoPath string) error {
204
223
func (g * gitService ) CreateAndCheckoutBranch (repoPath , branchName string ) error {
205
224
cmd := exec .Command ("git" , "checkout" , "-b" , branchName )
206
225
cmd .Dir = repoPath
226
+ log .Infof ("Executing Git command: %s" , cmd .String ())
207
227
if output , err := cmd .CombinedOutput (); err != nil {
228
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
208
229
return fmt .Errorf ("failed to create new branch %s: %w, output: %s" , branchName , err , string (output ))
209
230
}
210
231
return nil
@@ -214,7 +235,9 @@ func (g *gitService) CreateAndCheckoutBranch(repoPath, branchName string) error
214
235
func (g * gitService ) CheckoutBranch (repoPath , branchName string ) error {
215
236
cmd := exec .Command ("git" , "checkout" , branchName )
216
237
cmd .Dir = repoPath
238
+ log .Infof ("Executing Git command: %s" , cmd .String ())
217
239
if output , err := cmd .CombinedOutput (); err != nil {
240
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
218
241
return fmt .Errorf ("failed to checkout branch %s: %w, output: %s" , branchName , err , string (output ))
219
242
}
220
243
return nil
@@ -224,7 +247,9 @@ func (g *gitService) CheckoutBranch(repoPath, branchName string) error {
224
247
func (g * gitService ) CreateTrackingBranch (repoPath , branchName string ) error {
225
248
cmd := exec .Command ("git" , "checkout" , "-b" , branchName , fmt .Sprintf ("origin/%s" , branchName ))
226
249
cmd .Dir = repoPath
250
+ log .Infof ("Executing Git command: %s" , cmd .String ())
227
251
if output , err := cmd .CombinedOutput (); err != nil {
252
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , cmd .String (), string (output ), err )
228
253
return fmt .Errorf ("failed to create tracking branch %s: %w, output: %s" , branchName , err , string (output ))
229
254
}
230
255
return nil
@@ -245,14 +270,18 @@ func (g *gitService) FetchAndCheckoutPR(repoPath string, prNumber int) error {
245
270
// Step 1: First fetch the PR content to FETCH_HEAD without creating/updating local branch
246
271
fetchCmd := exec .Command ("git" , "fetch" , "origin" , fmt .Sprintf ("pull/%d/head" , prNumber ))
247
272
fetchCmd .Dir = repoPath
273
+ log .Infof ("Executing Git command: %s" , fetchCmd .String ())
248
274
if output , err := fetchCmd .CombinedOutput (); err != nil {
275
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , fetchCmd .String (), string (output ), err )
249
276
return fmt .Errorf ("failed to fetch PR #%d content: %w, output: %s" , prNumber , err , string (output ))
250
277
}
251
278
252
279
// Step 2: Reset current branch to the fetched content
253
280
resetCmd := exec .Command ("git" , "reset" , "--hard" , "FETCH_HEAD" )
254
281
resetCmd .Dir = repoPath
282
+ log .Infof ("Executing Git command: %s" , resetCmd .String ())
255
283
if output , err := resetCmd .CombinedOutput (); err != nil {
284
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , resetCmd .String (), string (output ), err )
256
285
return fmt .Errorf ("failed to reset PR branch to latest content: %w, output: %s" , err , string (output ))
257
286
}
258
287
@@ -262,13 +291,17 @@ func (g *gitService) FetchAndCheckoutPR(repoPath string, prNumber int) error {
262
291
263
292
fetchCmd := exec .Command ("git" , "fetch" , "origin" , fmt .Sprintf ("pull/%d/head:%s" , prNumber , prBranchName ), "--force" )
264
293
fetchCmd .Dir = repoPath
294
+ log .Infof ("Executing Git command: %s" , fetchCmd .String ())
265
295
if output , err := fetchCmd .CombinedOutput (); err != nil {
296
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , fetchCmd .String (), string (output ), err )
266
297
return fmt .Errorf ("failed to fetch PR #%d: %w, output: %s" , prNumber , err , string (output ))
267
298
}
268
299
269
300
checkoutCmd := exec .Command ("git" , "checkout" , prBranchName )
270
301
checkoutCmd .Dir = repoPath
302
+ log .Infof ("Executing Git command: %s" , checkoutCmd .String ())
271
303
if output , err := checkoutCmd .CombinedOutput (); err != nil {
304
+ log .Errorf ("Git command failed: %s, output: %s, error: %v" , checkoutCmd .String (), string (output ), err )
272
305
return fmt .Errorf ("failed to checkout PR branch %s: %w, output: %s" , prBranchName , err , string (output ))
273
306
}
274
307
0 commit comments