mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Backport #33319 Fix #33271 The only conflict is `reqctx` in `services/repository/merge_upstream.go`, which could keep using `context.Context` in 1.23
This commit is contained in:
@@ -60,25 +60,54 @@ func TestRepoMergeUpstream(t *testing.T) {
|
||||
|
||||
t.Run("HeadBeforeBase", func(t *testing.T) {
|
||||
// add a file in base repo
|
||||
sessionBaseUser := loginUser(t, baseUser.Name)
|
||||
require.NoError(t, createOrReplaceFileInBranch(baseUser, baseRepo, "new-file.txt", "master", "test-content-1"))
|
||||
|
||||
// the repo shows a prompt to "sync fork"
|
||||
var mergeUpstreamLink string
|
||||
require.Eventually(t, func() bool {
|
||||
resp := session.MakeRequest(t, NewRequestf(t, "GET", "/%s/test-repo-fork/src/branch/fork-branch", forkUser.Name), http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
mergeUpstreamLink = queryMergeUpstreamButtonLink(htmlDoc)
|
||||
if mergeUpstreamLink == "" {
|
||||
return false
|
||||
}
|
||||
respMsg, _ := htmlDoc.Find(".ui.message:not(.positive)").Html()
|
||||
return strings.Contains(respMsg, `This branch is 1 commit behind <a href="/user2/repo1/src/branch/master">user2/repo1:master</a>`)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
t.Run("DetectDefaultBranch", func(t *testing.T) {
|
||||
// the repo shows a prompt to "sync fork" (defaults to the default branch)
|
||||
require.Eventually(t, func() bool {
|
||||
resp := session.MakeRequest(t, NewRequestf(t, "GET", "/%s/test-repo-fork/src/branch/fork-branch", forkUser.Name), http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
mergeUpstreamLink = queryMergeUpstreamButtonLink(htmlDoc)
|
||||
if mergeUpstreamLink == "" {
|
||||
return false
|
||||
}
|
||||
respMsg, _ := htmlDoc.Find(".ui.message:not(.positive)").Html()
|
||||
return strings.Contains(respMsg, `This branch is 1 commit behind <a href="/user2/repo1/src/branch/master">user2/repo1:master</a>`)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
|
||||
t.Run("DetectSameBranch", func(t *testing.T) {
|
||||
// if the fork-branch name also exists in the base repo, then use that branch instead
|
||||
req = NewRequestWithValues(t, "POST", "/user2/repo1/branches/_new/branch/master", map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, sessionBaseUser),
|
||||
"new_branch_name": "fork-branch",
|
||||
})
|
||||
sessionBaseUser.MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
resp := session.MakeRequest(t, NewRequestf(t, "GET", "/%s/test-repo-fork/src/branch/fork-branch", forkUser.Name), http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
mergeUpstreamLink = queryMergeUpstreamButtonLink(htmlDoc)
|
||||
if mergeUpstreamLink == "" {
|
||||
return false
|
||||
}
|
||||
respMsg, _ := htmlDoc.Find(".ui.message:not(.positive)").Html()
|
||||
return strings.Contains(respMsg, `This branch is 1 commit behind <a href="/user2/repo1/src/branch/fork-branch">user2/repo1:fork-branch</a>`)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
|
||||
// click the "sync fork" button
|
||||
req = NewRequestWithValues(t, "POST", mergeUpstreamLink, map[string]string{"_csrf": GetUserCSRFToken(t, session)})
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
checkFileContent("fork-branch", "test-content-1")
|
||||
|
||||
// delete the "fork-branch" from the base repo
|
||||
req = NewRequestWithValues(t, "POST", "/user2/repo1/branches/delete?name=fork-branch", map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, sessionBaseUser),
|
||||
})
|
||||
sessionBaseUser.MakeRequest(t, req, http.StatusOK)
|
||||
})
|
||||
|
||||
t.Run("BaseChangeAfterHeadChange", func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user