Backport #37783 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
+35
-23
@@ -714,6 +714,8 @@ func indexCommit(commits []*git.Commit, commitID string) *git.Commit {
|
|||||||
|
|
||||||
// ViewPullFiles render pull request changed files list page
|
// ViewPullFiles render pull request changed files list page
|
||||||
func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
|
func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
|
||||||
|
var err error
|
||||||
|
|
||||||
ctx.Data["PageIsPullList"] = true
|
ctx.Data["PageIsPullList"] = true
|
||||||
ctx.Data["PageIsPullFiles"] = true
|
ctx.Data["PageIsPullFiles"] = true
|
||||||
|
|
||||||
@@ -740,43 +742,53 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isSingleCommit := beforeCommitID == "" && afterCommitID != ""
|
isSingleCommit := beforeCommitID == "" && afterCommitID != ""
|
||||||
ctx.Data["IsShowingOnlySingleCommit"] = isSingleCommit
|
// FIXME: when afterCommitID==headCommitID, isSingleCommit and isShowAllCommits can be both true, which doesn't seem right
|
||||||
isShowAllCommits := (beforeCommitID == "" || beforeCommitID == prInfo.MergeBase) && (afterCommitID == "" || afterCommitID == headCommitID)
|
isShowAllCommits := (beforeCommitID == "" || beforeCommitID == prInfo.MergeBase) && (afterCommitID == "" || afterCommitID == headCommitID)
|
||||||
|
|
||||||
|
ctx.Data["IsShowingOnlySingleCommit"] = isSingleCommit
|
||||||
ctx.Data["IsShowingAllCommits"] = isShowAllCommits
|
ctx.Data["IsShowingAllCommits"] = isShowAllCommits
|
||||||
|
|
||||||
if afterCommitID == "" || afterCommitID == headCommitID {
|
// "commits list" is half-open, half-closed: (base, head]
|
||||||
afterCommitID = headCommitID
|
// * base commit is not in the list
|
||||||
}
|
// * if the PR is empty, the list is also empty (head commit is not in the list)
|
||||||
|
|
||||||
|
afterCommitID = util.IfZero(afterCommitID, headCommitID)
|
||||||
afterCommit := indexCommit(prInfo.Commits, afterCommitID)
|
afterCommit := indexCommit(prInfo.Commits, afterCommitID)
|
||||||
|
if afterCommit == nil && afterCommitID == headCommitID {
|
||||||
|
afterCommit, err = gitRepo.GetCommit(afterCommitID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("GetCommit(afterCommitID)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
if afterCommit == nil {
|
if afterCommit == nil {
|
||||||
ctx.HTTPError(http.StatusBadRequest, "after commit not found in PR commits")
|
ctx.NotFound(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var beforeCommit *git.Commit
|
var beforeCommit *git.Commit
|
||||||
if !isSingleCommit {
|
if isSingleCommit {
|
||||||
if beforeCommitID == "" || beforeCommitID == prInfo.MergeBase {
|
|
||||||
beforeCommitID = prInfo.MergeBase
|
|
||||||
// mergebase commit is not in the list of the pull request commits
|
|
||||||
beforeCommit, err = gitRepo.GetCommit(beforeCommitID)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("GetCommit", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
beforeCommit = indexCommit(prInfo.Commits, beforeCommitID)
|
|
||||||
if beforeCommit == nil {
|
|
||||||
ctx.HTTPError(http.StatusBadRequest, "before commit not found in PR commits")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
beforeCommit, err = afterCommit.Parent(0)
|
beforeCommit, err = afterCommit.Parent(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Parent", err)
|
ctx.ServerError("afterCommit.Parent", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
beforeCommitID = beforeCommit.ID.String()
|
beforeCommitID = beforeCommit.ID.String()
|
||||||
|
} else {
|
||||||
|
beforeCommitID = util.IfZero(beforeCommitID, prInfo.MergeBase)
|
||||||
|
beforeCommit = indexCommit(prInfo.Commits, beforeCommitID)
|
||||||
|
if beforeCommit == nil && beforeCommitID == prInfo.MergeBase {
|
||||||
|
// mergebase commit is not in the list of the pull request commits
|
||||||
|
beforeCommit, err = gitRepo.GetCommit(beforeCommitID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("GetCommit(beforeCommitID)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if beforeCommit == nil {
|
||||||
|
ctx.NotFound(nil)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||||
|
|||||||
@@ -141,21 +141,29 @@ func TestPullCreate_EmptyChangesWithDifferentCommits(t *testing.T) {
|
|||||||
func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) {
|
func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) {
|
||||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
session := loginUser(t, "user1")
|
session := loginUser(t, "user1")
|
||||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "")
|
|
||||||
testCreateBranch(t, session, "user1", "repo1", "branch/master", "status1", http.StatusSeeOther)
|
|
||||||
url := path.Join("user1", "repo1", "compare", "master...status1")
|
|
||||||
req := NewRequestWithValues(t, "POST", url,
|
|
||||||
map[string]string{
|
|
||||||
"title": "pull request from status1",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
session.MakeRequest(t, req, http.StatusOK)
|
|
||||||
req = NewRequest(t, "GET", "/user1/repo1/pulls/1")
|
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
|
||||||
|
|
||||||
|
testCreateBranch(t, session, "user2", "repo1", "branch/master", "empty-pr-branch", http.StatusSeeOther)
|
||||||
|
resp := testPullCreateDirectly(t, session, createPullRequestOptions{
|
||||||
|
BaseRepoOwner: "user2",
|
||||||
|
BaseRepoName: "repo1",
|
||||||
|
BaseBranch: "master",
|
||||||
|
HeadBranch: "empty-pr-branch",
|
||||||
|
Title: "empty pr test",
|
||||||
|
})
|
||||||
|
prURL := test.RedirectURL(resp)
|
||||||
|
|
||||||
|
// check the "merge box" text
|
||||||
|
req := NewRequest(t, "GET", prURL)
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
text := strings.TrimSpace(doc.doc.Find(".merge-section").Text())
|
text := strings.TrimSpace(doc.doc.Find(".merge-section").Text())
|
||||||
assert.Contains(t, text, "This branch is already included in the target branch. There is nothing to merge.")
|
assert.Contains(t, text, "This branch is already included in the target branch. There is nothing to merge.")
|
||||||
|
|
||||||
|
// check the "files" tab content
|
||||||
|
req = NewRequest(t, "GET", prURL+"/files")
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
doc = NewHTMLParser(t, resp.Body)
|
||||||
|
assert.Equal(t, "Diff Content Not Available", strings.TrimSpace(doc.Find("#diff-container").Text()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user