@@ -10,7 +10,6 @@ import (
10
10
"context"
11
11
"encoding/json"
12
12
"fmt"
13
- "path/filepath"
14
13
"strings"
15
14
"time"
16
15
@@ -20,7 +19,6 @@ import (
20
19
"code.gitea.io/gitea/modules/log"
21
20
"code.gitea.io/gitea/modules/notification"
22
21
"code.gitea.io/gitea/modules/setting"
23
- "code.gitea.io/gitea/modules/util"
24
22
issue_service "code.gitea.io/gitea/services/issue"
25
23
26
24
"github.com/unknwon/com"
@@ -215,18 +213,6 @@ func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *m
215
213
return nil
216
214
}
217
215
218
- func addHeadRepoTasks (prs []* models.PullRequest ) {
219
- for _ , pr := range prs {
220
- log .Trace ("addHeadRepoTasks[%d]: composing new test task" , pr .ID )
221
- if err := PushToBaseRepo (pr ); err != nil {
222
- log .Error ("PushToBaseRepo: %v" , err )
223
- continue
224
- }
225
-
226
- AddToTaskQueue (pr )
227
- }
228
- }
229
-
230
216
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
231
217
// and generate new patch for testing as needed.
232
218
func AddTestPullRequestTask (doer * models.User , repoID int64 , branch string , isSync bool , oldCommitID , newCommitID string ) {
@@ -283,8 +269,14 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
283
269
}
284
270
}
285
271
286
- addHeadRepoTasks (prs )
287
272
for _ , pr := range prs {
273
+ log .Trace ("Updating PR[%d]: composing new test task" , pr .ID )
274
+ if err := PushToBaseRepo (pr ); err != nil {
275
+ log .Error ("PushToBaseRepo: %v" , err )
276
+ continue
277
+ }
278
+
279
+ AddToTaskQueue (pr )
288
280
comment , err := models .CreatePushPullComment (doer , pr , oldCommitID , newCommitID )
289
281
if err == nil && comment != nil {
290
282
notification .NotifyPullRequestPushCommits (doer , pr , comment )
@@ -389,54 +381,17 @@ func checkIfPRContentChanged(pr *models.PullRequest, oldCommitID, newCommitID st
389
381
func PushToBaseRepo (pr * models.PullRequest ) (err error ) {
390
382
log .Trace ("PushToBaseRepo[%d]: pushing commits to base repo '%s'" , pr .BaseRepoID , pr .GetGitRefName ())
391
383
392
- // Clone base repo.
393
- tmpBasePath , err := models .CreateTemporaryPath ("pull" )
394
- if err != nil {
395
- log .Error ("CreateTemporaryPath: %v" , err )
396
- return err
397
- }
398
- defer func () {
399
- err := models .RemoveTemporaryPath (tmpBasePath )
400
- if err != nil {
401
- log .Error ("Error whilst removing temporary path: %s Error: %v" , tmpBasePath , err )
402
- }
403
- }()
404
-
405
384
if err := pr .LoadHeadRepo (); err != nil {
406
385
log .Error ("Unable to load head repository for PR[%d] Error: %v" , pr .ID , err )
407
386
return err
408
387
}
409
388
headRepoPath := pr .HeadRepo .RepoPath ()
410
389
411
- if err := git .Clone (headRepoPath , tmpBasePath , git.CloneRepoOptions {
412
- Bare : true ,
413
- Shared : true ,
414
- Branch : pr .HeadBranch ,
415
- Quiet : true ,
416
- }); err != nil {
417
- log .Error ("git clone tmpBasePath: %v" , err )
418
- return err
419
- }
420
- gitRepo , err := git .OpenRepository (tmpBasePath )
421
- if err != nil {
422
- return fmt .Errorf ("OpenRepository: %v" , err )
423
- }
424
- defer gitRepo .Close ()
425
-
426
390
if err := pr .LoadBaseRepo (); err != nil {
427
391
log .Error ("Unable to load base repository for PR[%d] Error: %v" , pr .ID , err )
428
392
return err
429
393
}
430
- if err := gitRepo .AddRemote ("base" , pr .BaseRepo .RepoPath (), false ); err != nil {
431
- return fmt .Errorf ("tmpGitRepo.AddRemote: %v" , err )
432
- }
433
-
434
- headFile := pr .GetGitRefName ()
435
-
436
- // Remove head in case there is a conflict.
437
- file := filepath .Join (pr .BaseRepo .RepoPath (), headFile )
438
-
439
- _ = util .Remove (file )
394
+ baseRepoPath := pr .BaseRepo .RepoPath ()
440
395
441
396
if err = pr .LoadIssue (); err != nil {
442
397
return fmt .Errorf ("unable to load issue %d for pr %d: %v" , pr .IssueID , pr .ID , err )
@@ -445,24 +400,26 @@ func PushToBaseRepo(pr *models.PullRequest) (err error) {
445
400
return fmt .Errorf ("unable to load poster %d for pr %d: %v" , pr .Issue .PosterID , pr .ID , err )
446
401
}
447
402
448
- if err = git .Push (tmpBasePath , git.PushOptions {
449
- Remote : "base" ,
450
- Branch : fmt .Sprintf ("%s:%s" , pr .HeadBranch , headFile ),
403
+ gitRefName := pr .GetGitRefName ()
404
+
405
+ if err := git .Push (headRepoPath , git.PushOptions {
406
+ Remote : baseRepoPath ,
407
+ Branch : pr .HeadBranch + ":" + gitRefName ,
451
408
Force : true ,
452
409
// Use InternalPushingEnvironment here because we know that pre-receive and post-receive do not run on a refs/pulls/...
453
410
Env : models .InternalPushingEnvironment (pr .Issue .Poster , pr .BaseRepo ),
454
411
}); err != nil {
455
412
if git .IsErrPushOutOfDate (err ) {
456
413
// This should not happen as we're using force!
457
- log .Error ("Unable to push PR head for %s#%d (%-v:%s) due to ErrPushOfDate: %v" , pr .BaseRepo .FullName (), pr .Index , pr .BaseRepo , headFile , err )
414
+ log .Error ("Unable to push PR head for %s#%d (%-v:%s) due to ErrPushOfDate: %v" , pr .BaseRepo .FullName (), pr .Index , pr .BaseRepo , gitRefName , err )
458
415
return err
459
416
} else if git .IsErrPushRejected (err ) {
460
417
rejectErr := err .(* git.ErrPushRejected )
461
- log .Info ("Unable to push PR head for %s#%d (%-v:%s) due to rejection:\n Stdout: %s\n Stderr: %s\n Error: %v" , pr .BaseRepo .FullName (), pr .Index , pr .BaseRepo , headFile , rejectErr .StdOut , rejectErr .StdErr , rejectErr .Err )
418
+ log .Info ("Unable to push PR head for %s#%d (%-v:%s) due to rejection:\n Stdout: %s\n Stderr: %s\n Error: %v" , pr .BaseRepo .FullName (), pr .Index , pr .BaseRepo , gitRefName , rejectErr .StdOut , rejectErr .StdErr , rejectErr .Err )
462
419
return err
463
420
}
464
- log .Error ("Unable to push PR head for %s#%d (%-v:%s) due to Error: %v" , pr .BaseRepo .FullName (), pr .Index , pr .BaseRepo , headFile , err )
465
- return fmt .Errorf ("Push: %s:%s %s:%s %v" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), headFile , err )
421
+ log .Error ("Unable to push PR head for %s#%d (%-v:%s) due to Error: %v" , pr .BaseRepo .FullName (), pr .Index , pr .BaseRepo , gitRefName , err )
422
+ return fmt .Errorf ("Push: %s:%s %s:%s %v" , pr .HeadRepo .FullName (), pr .HeadBranch , pr .BaseRepo .FullName (), gitRefName , err )
466
423
}
467
424
468
425
return nil
0 commit comments