@@ -60,25 +60,54 @@ 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
+ sessionBaseUser := loginUser (t , baseUser .Name )
63
64
require .NoError (t , createOrReplaceFileInBranch (baseUser , baseRepo , "new-file.txt" , "master" , "test-content-1" ))
64
65
65
- // the repo shows a prompt to "sync fork"
66
66
var mergeUpstreamLink string
67
- require .Eventually (t , func () bool {
68
- resp := session .MakeRequest (t , NewRequestf (t , "GET" , "/%s/test-repo-fork/src/branch/fork-branch" , forkUser .Name ), http .StatusOK )
69
- htmlDoc := NewHTMLParser (t , resp .Body )
70
- mergeUpstreamLink = queryMergeUpstreamButtonLink (htmlDoc )
71
- if mergeUpstreamLink == "" {
72
- return false
73
- }
74
- respMsg , _ := htmlDoc .Find (".ui.message:not(.positive)" ).Html ()
75
- return strings .Contains (respMsg , `This branch is 1 commit behind <a href="/user2/repo1/src/branch/master">user2/repo1:master</a>` )
76
- }, 5 * time .Second , 100 * time .Millisecond )
67
+ t .Run ("DetectDefaultBranch" , func (t * testing.T ) {
68
+ // the repo shows a prompt to "sync fork" (defaults to the default branch)
69
+ require .Eventually (t , func () bool {
70
+ resp := session .MakeRequest (t , NewRequestf (t , "GET" , "/%s/test-repo-fork/src/branch/fork-branch" , forkUser .Name ), http .StatusOK )
71
+ htmlDoc := NewHTMLParser (t , resp .Body )
72
+ mergeUpstreamLink = queryMergeUpstreamButtonLink (htmlDoc )
73
+ if mergeUpstreamLink == "" {
74
+ return false
75
+ }
76
+ respMsg , _ := htmlDoc .Find (".ui.message:not(.positive)" ).Html ()
77
+ return strings .Contains (respMsg , `This branch is 1 commit behind <a href="/user2/repo1/src/branch/master">user2/repo1:master</a>` )
78
+ }, 5 * time .Second , 100 * time .Millisecond )
79
+ })
80
+
81
+ t .Run ("DetectSameBranch" , func (t * testing.T ) {
82
+ // if the fork-branch name also exists in the base repo, then use that branch instead
83
+ req = NewRequestWithValues (t , "POST" , "/user2/repo1/branches/_new/branch/master" , map [string ]string {
84
+ "_csrf" : GetUserCSRFToken (t , sessionBaseUser ),
85
+ "new_branch_name" : "fork-branch" ,
86
+ })
87
+ sessionBaseUser .MakeRequest (t , req , http .StatusSeeOther )
88
+
89
+ require .Eventually (t , func () bool {
90
+ resp := session .MakeRequest (t , NewRequestf (t , "GET" , "/%s/test-repo-fork/src/branch/fork-branch" , forkUser .Name ), http .StatusOK )
91
+ htmlDoc := NewHTMLParser (t , resp .Body )
92
+ mergeUpstreamLink = queryMergeUpstreamButtonLink (htmlDoc )
93
+ if mergeUpstreamLink == "" {
94
+ return false
95
+ }
96
+ respMsg , _ := htmlDoc .Find (".ui.message:not(.positive)" ).Html ()
97
+ return strings .Contains (respMsg , `This branch is 1 commit behind <a href="/user2/repo1/src/branch/fork-branch">user2/repo1:fork-branch</a>` )
98
+ }, 5 * time .Second , 100 * time .Millisecond )
99
+ })
77
100
78
101
// click the "sync fork" button
79
102
req = NewRequestWithValues (t , "POST" , mergeUpstreamLink , map [string ]string {"_csrf" : GetUserCSRFToken (t , session )})
80
103
session .MakeRequest (t , req , http .StatusOK )
81
104
checkFileContent ("fork-branch" , "test-content-1" )
105
+
106
+ // delete the "fork-branch" from the base repo
107
+ req = NewRequestWithValues (t , "POST" , "/user2/repo1/branches/delete?name=fork-branch" , map [string ]string {
108
+ "_csrf" : GetUserCSRFToken (t , sessionBaseUser ),
109
+ })
110
+ sessionBaseUser .MakeRequest (t , req , http .StatusOK )
82
111
})
83
112
84
113
t .Run ("BaseChangeAfterHeadChange" , func (t * testing.T ) {
0 commit comments