@@ -188,43 +188,79 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
188
188
}
189
189
190
190
// Switch off LFS process (set required, clean and smudge here also)
191
- if err := gitConfigCommand ().AddArguments ("filter.lfs.process" , "" ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
191
+ if err := gitConfigCommand ().AddArguments ("filter.lfs.process" , "" ).
192
+ RunWithContext (& git.RunContext {
193
+ Timeout : - 1 ,
194
+ Dir : tmpBasePath ,
195
+ Stdout : & outbuf ,
196
+ Stderr : & errbuf ,
197
+ }); err != nil {
192
198
log .Error ("git config [filter.lfs.process -> <> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
193
199
return "" , fmt .Errorf ("git config [filter.lfs.process -> <> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
194
200
}
195
201
outbuf .Reset ()
196
202
errbuf .Reset ()
197
203
198
- if err := gitConfigCommand ().AddArguments ("filter.lfs.required" , "false" ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
204
+ if err := gitConfigCommand ().AddArguments ("filter.lfs.required" , "false" ).
205
+ RunWithContext (& git.RunContext {
206
+ Timeout : - 1 ,
207
+ Dir : tmpBasePath ,
208
+ Stdout : & outbuf ,
209
+ Stderr : & errbuf ,
210
+ }); err != nil {
199
211
log .Error ("git config [filter.lfs.required -> <false> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
200
212
return "" , fmt .Errorf ("git config [filter.lfs.required -> <false> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
201
213
}
202
214
outbuf .Reset ()
203
215
errbuf .Reset ()
204
216
205
- if err := gitConfigCommand ().AddArguments ("filter.lfs.clean" , "" ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
217
+ if err := gitConfigCommand ().AddArguments ("filter.lfs.clean" , "" ).
218
+ RunWithContext (& git.RunContext {
219
+ Timeout : - 1 ,
220
+ Dir : tmpBasePath ,
221
+ Stdout : & outbuf ,
222
+ Stderr : & errbuf ,
223
+ }); err != nil {
206
224
log .Error ("git config [filter.lfs.clean -> <> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
207
225
return "" , fmt .Errorf ("git config [filter.lfs.clean -> <> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
208
226
}
209
227
outbuf .Reset ()
210
228
errbuf .Reset ()
211
229
212
- if err := gitConfigCommand ().AddArguments ("filter.lfs.smudge" , "" ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
230
+ if err := gitConfigCommand ().AddArguments ("filter.lfs.smudge" , "" ).
231
+ RunWithContext (& git.RunContext {
232
+ Timeout : - 1 ,
233
+ Dir : tmpBasePath ,
234
+ Stdout : & outbuf ,
235
+ Stderr : & errbuf ,
236
+ }); err != nil {
213
237
log .Error ("git config [filter.lfs.smudge -> <> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
214
238
return "" , fmt .Errorf ("git config [filter.lfs.smudge -> <> ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
215
239
}
216
240
outbuf .Reset ()
217
241
errbuf .Reset ()
218
242
219
- if err := gitConfigCommand ().AddArguments ("core.sparseCheckout" , "true" ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
243
+ if err := gitConfigCommand ().AddArguments ("core.sparseCheckout" , "true" ).
244
+ RunWithContext (& git.RunContext {
245
+ Timeout : - 1 ,
246
+ Dir : tmpBasePath ,
247
+ Stdout : & outbuf ,
248
+ Stderr : & errbuf ,
249
+ }); err != nil {
220
250
log .Error ("git config [core.sparseCheckout -> true ]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
221
251
return "" , fmt .Errorf ("git config [core.sparsecheckout -> true]: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
222
252
}
223
253
outbuf .Reset ()
224
254
errbuf .Reset ()
225
255
226
256
// Read base branch index
227
- if err := git .NewCommand (ctx , "read-tree" , "HEAD" ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
257
+ if err := git .NewCommand (ctx , "read-tree" , "HEAD" ).
258
+ RunWithContext (& git.RunContext {
259
+ Timeout : - 1 ,
260
+ Dir : tmpBasePath ,
261
+ Stdout : & outbuf ,
262
+ Stderr : & errbuf ,
263
+ }); err != nil {
228
264
log .Error ("git read-tree HEAD: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
229
265
return "" , fmt .Errorf ("Unable to read base branch in to the index: %v\n %s\n %s" , err , outbuf .String (), errbuf .String ())
230
266
}
@@ -279,15 +315,27 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
279
315
fallthrough
280
316
case repo_model .MergeStyleRebaseMerge :
281
317
// Checkout head branch
282
- if err := git .NewCommand (ctx , "checkout" , "-b" , stagingBranch , trackingBranch ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
318
+ if err := git .NewCommand (ctx , "checkout" , "-b" , stagingBranch , trackingBranch ).
319
+ RunWithContext (& git.RunContext {
320
+ Timeout : - 1 ,
321
+ Dir : tmpBasePath ,
322
+ Stdout : & outbuf ,
323
+ Stderr : & errbuf ,
324
+ }); err != nil {
283
325
log .Error ("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
284
326
return "" , fmt .Errorf ("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
285
327
}
286
328
outbuf .Reset ()
287
329
errbuf .Reset ()
288
330
289
331
// Rebase before merging
290
- if err := git .NewCommand (ctx , "rebase" , baseBranch ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
332
+ if err := git .NewCommand (ctx , "rebase" , baseBranch ).
333
+ RunWithContext (& git.RunContext {
334
+ Timeout : - 1 ,
335
+ Dir : tmpBasePath ,
336
+ Stdout : & outbuf ,
337
+ Stderr : & errbuf ,
338
+ }); err != nil {
291
339
// Rebase will leave a REBASE_HEAD file in .git if there is a conflict
292
340
if _ , statErr := os .Stat (filepath .Join (tmpBasePath , ".git" , "REBASE_HEAD" )); statErr == nil {
293
341
var commitSha string
@@ -335,7 +383,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
335
383
}
336
384
337
385
// Checkout base branch again
338
- if err := git .NewCommand (ctx , "checkout" , baseBranch ).RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
386
+ if err := git .NewCommand (ctx , "checkout" , baseBranch ).
387
+ RunWithContext (& git.RunContext {
388
+ Timeout : - 1 ,
389
+ Dir : tmpBasePath ,
390
+ Stdout : & outbuf ,
391
+ Stderr : & errbuf ,
392
+ }); err != nil {
339
393
log .Error ("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
340
394
return "" , fmt .Errorf ("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
341
395
}
@@ -375,7 +429,14 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
375
429
}
376
430
sig := pr .Issue .Poster .NewGitSig ()
377
431
if signArg == "" {
378
- if err := git .NewCommand (ctx , "commit" , fmt .Sprintf ("--author='%s <%s>'" , sig .Name , sig .Email ), "-m" , message ).RunInDirTimeoutEnvPipeline (env , - 1 , tmpBasePath , & outbuf , & errbuf ); err != nil {
432
+ if err := git .NewCommand (ctx , "commit" , fmt .Sprintf ("--author='%s <%s>'" , sig .Name , sig .Email ), "-m" , message ).
433
+ RunWithContext (& git.RunContext {
434
+ Env : env ,
435
+ Timeout : - 1 ,
436
+ Dir : tmpBasePath ,
437
+ Stdout : & outbuf ,
438
+ Stderr : & errbuf ,
439
+ }); err != nil {
379
440
log .Error ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
380
441
return "" , fmt .Errorf ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
381
442
}
@@ -384,7 +445,14 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
384
445
// add trailer
385
446
message += fmt .Sprintf ("\n Co-authored-by: %s\n Co-committed-by: %s\n " , sig .String (), sig .String ())
386
447
}
387
- if err := git .NewCommand (ctx , "commit" , signArg , fmt .Sprintf ("--author='%s <%s>'" , sig .Name , sig .Email ), "-m" , message ).RunInDirTimeoutEnvPipeline (env , - 1 , tmpBasePath , & outbuf , & errbuf ); err != nil {
448
+ if err := git .NewCommand (ctx , "commit" , signArg , fmt .Sprintf ("--author='%s <%s>'" , sig .Name , sig .Email ), "-m" , message ).
449
+ RunWithContext (& git.RunContext {
450
+ Env : env ,
451
+ Timeout : - 1 ,
452
+ Dir : tmpBasePath ,
453
+ Stdout : & outbuf ,
454
+ Stderr : & errbuf ,
455
+ }); err != nil {
388
456
log .Error ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
389
457
return "" , fmt .Errorf ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
390
458
}
@@ -448,7 +516,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
448
516
}
449
517
450
518
// Push back to upstream.
451
- if err := pushCmd .RunInDirTimeoutEnvPipeline (env , - 1 , tmpBasePath , & outbuf , & errbuf ); err != nil {
519
+ if err := pushCmd .RunWithContext (& git.RunContext {
520
+ Env : env ,
521
+ Timeout : - 1 ,
522
+ Dir : tmpBasePath ,
523
+ Stdout : & outbuf ,
524
+ Stderr : & errbuf ,
525
+ }); err != nil {
452
526
if strings .Contains (errbuf .String (), "non-fast-forward" ) {
453
527
return "" , & git.ErrPushOutOfDate {
454
528
StdOut : outbuf .String (),
@@ -475,12 +549,26 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
475
549
func commitAndSignNoAuthor (ctx context.Context , pr * models.PullRequest , message , signArg , tmpBasePath string , env []string ) error {
476
550
var outbuf , errbuf strings.Builder
477
551
if signArg == "" {
478
- if err := git .NewCommand (ctx , "commit" , "-m" , message ).RunInDirTimeoutEnvPipeline (env , - 1 , tmpBasePath , & outbuf , & errbuf ); err != nil {
552
+ if err := git .NewCommand (ctx , "commit" , "-m" , message ).
553
+ RunWithContext (& git.RunContext {
554
+ Env : env ,
555
+ Timeout : - 1 ,
556
+ Dir : tmpBasePath ,
557
+ Stdout : & outbuf ,
558
+ Stderr : & errbuf ,
559
+ }); err != nil {
479
560
log .Error ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
480
561
return fmt .Errorf ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
481
562
}
482
563
} else {
483
- if err := git .NewCommand (ctx , "commit" , signArg , "-m" , message ).RunInDirTimeoutEnvPipeline (env , - 1 , tmpBasePath , & outbuf , & errbuf ); err != nil {
564
+ if err := git .NewCommand (ctx , "commit" , signArg , "-m" , message ).
565
+ RunWithContext (& git.RunContext {
566
+ Env : env ,
567
+ Timeout : - 1 ,
568
+ Dir : tmpBasePath ,
569
+ Stdout : & outbuf ,
570
+ Stderr : & errbuf ,
571
+ }); err != nil {
484
572
log .Error ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
485
573
return fmt .Errorf ("git commit [%s:%s -> %s:%s]: %v\n %s\n %s" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), pr .BaseBranch , err , outbuf .String (), errbuf .String ())
486
574
}
@@ -490,7 +578,12 @@ func commitAndSignNoAuthor(ctx context.Context, pr *models.PullRequest, message,
490
578
491
579
func runMergeCommand (pr * models.PullRequest , mergeStyle repo_model.MergeStyle , cmd * git.Command , tmpBasePath string ) error {
492
580
var outbuf , errbuf strings.Builder
493
- if err := cmd .RunInDirPipeline (tmpBasePath , & outbuf , & errbuf ); err != nil {
581
+ if err := cmd .RunWithContext (& git.RunContext {
582
+ Timeout : - 1 ,
583
+ Dir : tmpBasePath ,
584
+ Stdout : & outbuf ,
585
+ Stderr : & errbuf ,
586
+ }); err != nil {
494
587
// Merge will leave a MERGE_HEAD file in the .git folder if there is a conflict
495
588
if _ , statErr := os .Stat (filepath .Join (tmpBasePath , ".git" , "MERGE_HEAD" )); statErr == nil {
496
589
// We have a merge conflict error
@@ -523,7 +616,13 @@ func getDiffTree(ctx context.Context, repoPath, baseBranch, headBranch string) (
523
616
getDiffTreeFromBranch := func (repoPath , baseBranch , headBranch string ) (string , error ) {
524
617
var outbuf , errbuf strings.Builder
525
618
// Compute the diff-tree for sparse-checkout
526
- if err := git .NewCommand (ctx , "diff-tree" , "--no-commit-id" , "--name-only" , "-r" , "-z" , "--root" , baseBranch , headBranch , "--" ).RunInDirPipeline (repoPath , & outbuf , & errbuf ); err != nil {
619
+ if err := git .NewCommand (ctx , "diff-tree" , "--no-commit-id" , "--name-only" , "-r" , "-z" , "--root" , baseBranch , headBranch , "--" ).
620
+ RunWithContext (& git.RunContext {
621
+ Timeout : - 1 ,
622
+ Dir : repoPath ,
623
+ Stdout : & outbuf ,
624
+ Stderr : & errbuf ,
625
+ }); err != nil {
527
626
return "" , fmt .Errorf ("git diff-tree [%s base:%s head:%s]: %s" , repoPath , baseBranch , headBranch , errbuf .String ())
528
627
}
529
628
return outbuf .String (), nil
0 commit comments