@@ -68,6 +68,7 @@ func testGit(t *testing.T, u *url.URL) {
68
68
rawTest (t , & httpContext , little , big , littleLFS , bigLFS )
69
69
mediaTest (t , & httpContext , little , big , littleLFS , bigLFS )
70
70
71
+ t .Run ("CreateAGitStylePull" , doCreateAGitStylePull (dstPath , & httpContext , "master" , "test/head" ))
71
72
t .Run ("BranchProtectMerge" , doBranchProtectPRMerge (& httpContext , dstPath ))
72
73
t .Run ("MergeFork" , func (t * testing.T ) {
73
74
defer PrintCurrentTest (t )()
@@ -108,6 +109,7 @@ func testGit(t *testing.T, u *url.URL) {
108
109
rawTest (t , & sshContext , little , big , littleLFS , bigLFS )
109
110
mediaTest (t , & sshContext , little , big , littleLFS , bigLFS )
110
111
112
+ t .Run ("CreateAGitStylePull" , doCreateAGitStylePull (dstPath , & sshContext , "master" , "test/head2" ))
111
113
t .Run ("BranchProtectMerge" , doBranchProtectPRMerge (& sshContext , dstPath ))
112
114
t .Run ("MergeFork" , func (t * testing.T ) {
113
115
defer PrintCurrentTest (t )()
@@ -544,3 +546,125 @@ func doBranchDelete(ctx APITestContext, owner, repo, branch string) func(*testin
544
546
ctx .Session .MakeRequest (t , req , http .StatusOK )
545
547
}
546
548
}
549
+
550
+ func doCreateAGitStylePull (dstPath string , ctx * APITestContext , baseBranch , headBranch string ) func (t * testing.T ) {
551
+ return func (t * testing.T ) {
552
+ defer PrintCurrentTest (t )()
553
+
554
+ var (
555
+ pr1 , pr2 * models.PullRequest
556
+ commit string
557
+ )
558
+ repo , err := models .GetRepositoryByOwnerAndName (ctx .Username , ctx .Reponame )
559
+ if ! assert .NoError (t , err ) {
560
+ return
561
+ }
562
+
563
+ t .Run ("CreateHeadBranch" , doGitCreateBranch (dstPath , headBranch ))
564
+
565
+ t .Run ("AddCommit" , func (t * testing.T ) {
566
+ err := ioutil .WriteFile (path .Join (dstPath , "test_file" ), []byte ("## test content" ), 0666 )
567
+ if ! assert .NoError (t , err ) {
568
+ return
569
+ }
570
+
571
+ err = git .AddChanges (dstPath , true )
572
+ assert .NoError (t , err )
573
+
574
+ err = git .CommitChanges (dstPath , git.CommitChangesOptions {
575
+ Committer : & git.Signature {
576
+
577
+ Name : "user2" ,
578
+ When : time .Now (),
579
+ },
580
+ Author : & git.Signature {
581
+
582
+ Name : "user2" ,
583
+ When : time .Now (),
584
+ },
585
+ Message : fmt .Sprintf ("Testing commit 1" ),
586
+ })
587
+ assert .NoError (t , err )
588
+ commit , err = git .GetRefCommitID (dstPath , "HEAD" )
589
+ assert .NoError (t , err )
590
+ })
591
+
592
+ t .Run ("Push" , func (t * testing.T ) {
593
+ _ , err := git .NewCommand ("push" , "origin" , "HEAD:refs/for/master" , "-o" , "topic=" + headBranch ).RunInDir (dstPath )
594
+ if ! assert .NoError (t , err ) {
595
+ return
596
+ }
597
+ pr1 = models .AssertExistsAndLoadBean (t , & models.PullRequest {
598
+ HeadRepoID : repo .ID ,
599
+ Style : models .PullRequestStyleAGit ,
600
+ }).(* models.PullRequest )
601
+ if ! assert .NotEmpty (t , pr1 ) {
602
+ return
603
+ }
604
+ prMsg , err := doAPIGetPullRequest (* ctx , ctx .Username , ctx .Reponame , pr1 .Index )(t )
605
+ if ! assert .NoError (t , err ) {
606
+ return
607
+ }
608
+ assert .Equal (t , "user2/" + headBranch , pr1 .HeadBranch )
609
+ assert .Equal (t , false , prMsg .HasMerged )
610
+ assert .Contains (t , "Testing commit 1" , prMsg .Body )
611
+ assert .Equal (t , commit , prMsg .Head .Sha )
612
+
613
+ _ , err = git .NewCommand ("push" , "origin" , "HEAD:refs/for/master/test/" + headBranch ).RunInDir (dstPath )
614
+ if ! assert .NoError (t , err ) {
615
+ return
616
+ }
617
+ pr2 = models .AssertExistsAndLoadBean (t , & models.PullRequest {
618
+ HeadRepoID : repo .ID ,
619
+ Index : pr1 .Index + 1 ,
620
+ Style : models .PullRequestStyleAGit ,
621
+ }).(* models.PullRequest )
622
+ assert .NotEmpty (t , pr2 )
623
+ })
624
+
625
+ t .Run ("AddCommit2" , func (t * testing.T ) {
626
+ err := ioutil .WriteFile (path .Join (dstPath , "test_file" ), []byte ("## test content \n ## test content 2" ), 0666 )
627
+ if ! assert .NoError (t , err ) {
628
+ return
629
+ }
630
+
631
+ err = git .AddChanges (dstPath , true )
632
+ assert .NoError (t , err )
633
+
634
+ err = git .CommitChanges (dstPath , git.CommitChangesOptions {
635
+ Committer : & git.Signature {
636
+
637
+ Name : "user2" ,
638
+ When : time .Now (),
639
+ },
640
+ Author : & git.Signature {
641
+
642
+ Name : "user2" ,
643
+ When : time .Now (),
644
+ },
645
+ Message : fmt .Sprintf ("Testing commit 2" ),
646
+ })
647
+ assert .NoError (t , err )
648
+ commit , err = git .GetRefCommitID (dstPath , "HEAD" )
649
+ assert .NoError (t , err )
650
+ })
651
+
652
+ t .Run ("Push2" , func (t * testing.T ) {
653
+ _ , err := git .NewCommand ("push" , "origin" , "HEAD:refs/for/master" , "-o" , "topic=" + headBranch ).RunInDir (dstPath )
654
+ if ! assert .NoError (t , err ) {
655
+ return
656
+ }
657
+ prMsg , err := doAPIGetPullRequest (* ctx , ctx .Username , ctx .Reponame , pr1 .Index )(t )
658
+ if ! assert .NoError (t , err ) {
659
+ return
660
+ }
661
+ assert .Equal (t , false , prMsg .HasMerged )
662
+ assert .Equal (t , commit , prMsg .Head .Sha )
663
+
664
+ _ , err = git .NewCommand ("push" , "origin" , "HEAD:refs/for/master/test/" + headBranch ).RunInDir (dstPath )
665
+ assert .NoError (t , err )
666
+ })
667
+ t .Run ("Merge" , doAPIMergePullRequest (* ctx , ctx .Username , ctx .Reponame , pr1 .Index ))
668
+ t .Run ("CheckoutMasterAgain" , doGitCheckoutBranch (dstPath , "master" ))
669
+ }
670
+ }
0 commit comments