4
4
package integration
5
5
6
6
import (
7
- "encoding/base64"
8
7
"fmt"
9
8
"net/http"
10
9
"net/url"
@@ -13,6 +12,8 @@ import (
13
12
"time"
14
13
15
14
auth_model "code.gitea.io/gitea/models/auth"
15
+ "code.gitea.io/gitea/models/db"
16
+ git_model "code.gitea.io/gitea/models/git"
16
17
repo_model "code.gitea.io/gitea/models/repo"
17
18
"code.gitea.io/gitea/models/unittest"
18
19
user_model "code.gitea.io/gitea/models/user"
@@ -36,7 +37,6 @@ func TestRepoMergeUpstream(t *testing.T) {
36
37
require .Equal (t , exp , resp .Body .String ())
37
38
}
38
39
39
- baseSession := loginUser (t , baseUser .Name )
40
40
session := loginUser (t , forkUser .Name )
41
41
token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository )
42
42
@@ -60,7 +60,7 @@ func TestRepoMergeUpstream(t *testing.T) {
60
60
61
61
t .Run ("HeadBeforeBase" , func (t * testing.T ) {
62
62
// add a file in base repo
63
- testAPINewFile (t , baseSession , baseRepo . OwnerName , baseRepo . Name , "master" , " new-file.txt" , "test-content-1" )
63
+ require . NoError (t , createOrReplaceFileInBranch ( baseUser , baseRepo , " new-file.txt" , "master" , " test-content-1") )
64
64
65
65
// the repo shows a prompt to "sync fork"
66
66
var mergeUpstreamLink string
@@ -83,21 +83,14 @@ func TestRepoMergeUpstream(t *testing.T) {
83
83
84
84
t .Run ("BaseChangeAfterHeadChange" , func (t * testing.T ) {
85
85
// update the files: base first, head later, and check the prompt
86
- testAPINewFile (t , session , forkRepo .OwnerName , forkRepo .Name , "fork-branch" , "new-file-other.txt" , "test-content-other" )
87
- baseUserToken := getTokenForLoggedInUser (t , baseSession , auth_model .AccessTokenScopeWriteRepository )
88
- req := NewRequestWithJSON (t , "PUT" , fmt .Sprintf ("/api/v1/repos/%s/%s/contents/%s" , baseRepo .OwnerName , baseRepo .Name , "new-file.txt" ), & api.UpdateFileOptions {
89
- DeleteFileOptions : api.DeleteFileOptions {
90
- FileOptions : api.FileOptions {
91
- BranchName : "master" ,
92
- NewBranchName : "master" ,
93
- Message : "Update new-file.txt" ,
94
- },
95
- SHA : "a4007b6679563f949751ed31bb371fdfb3194446" ,
96
- },
97
- ContentBase64 : base64 .StdEncoding .EncodeToString ([]byte ("test-content-2" )),
98
- }).
99
- AddTokenAuth (baseUserToken )
100
- MakeRequest (t , req , http .StatusOK )
86
+ require .NoError (t , createOrReplaceFileInBranch (baseUser , baseRepo , "new-file.txt" , "master" , "test-content-2" ))
87
+ require .NoError (t , createOrReplaceFileInBranch (forkUser , forkRepo , "new-file-other.txt" , "fork-branch" , "test-content-other" ))
88
+
89
+ // make sure the base branch's update time is before the fork, to make it test the complete logic
90
+ baseBranch := unittest .AssertExistsAndLoadBean (t , & git_model.Branch {RepoID : baseRepo .ID , Name : "master" })
91
+ forkBranch := unittest .AssertExistsAndLoadBean (t , & git_model.Branch {RepoID : forkRepo .ID , Name : "fork-branch" })
92
+ _ , err := db .GetEngine (db .DefaultContext ).ID (forkBranch .ID ).Update (& git_model.Branch {UpdatedUnix : baseBranch .UpdatedUnix + 1 })
93
+ require .NoError (t , err )
101
94
102
95
// the repo shows a prompt to "sync fork"
103
96
require .Eventually (t , func () bool {
0 commit comments