Fix pull creation with empty changes (#7920)
* Logs the stderr of git-apply * Add an integration test * Skip testPatch when patch is empty
This commit is contained in:
parent
31f5713a1f
commit
3ac45e3cb5
2 changed files with 36 additions and 7 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
@ -93,3 +94,28 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullCreate_EmptyChangesWithCommits(t *testing.T) {
|
||||||
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
|
session := loginUser(t, "user1")
|
||||||
|
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
||||||
|
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "status1", "README.md", "status1")
|
||||||
|
testEditFileToNewBranch(t, session, "user1", "repo1", "status1", "status1", "README.md", "# repo1\n\nDescription for repo1")
|
||||||
|
|
||||||
|
url := path.Join("user1", "repo1", "compare", "master...status1")
|
||||||
|
req := NewRequestWithValues(t, "POST", url,
|
||||||
|
map[string]string{
|
||||||
|
"_csrf": GetCSRF(t, session, url),
|
||||||
|
"title": "pull request from status1",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
session.MakeRequest(t, req, http.StatusFound)
|
||||||
|
|
||||||
|
req = NewRequest(t, "GET", "/user1/repo1/pulls/1")
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
|
text := strings.TrimSpace(doc.doc.Find(".item.text.green").Text())
|
||||||
|
assert.EqualValues(t, "This pull request can be merged automatically.", text)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -598,7 +598,7 @@ func (pr *PullRequest) testPatch(e Engine) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for i := range patchConflicts {
|
for i := range patchConflicts {
|
||||||
if strings.Contains(stderr, patchConflicts[i]) {
|
if strings.Contains(stderr, patchConflicts[i]) {
|
||||||
log.Trace("PullRequest[%d].testPatch (apply): has conflict", pr.ID)
|
log.Trace("PullRequest[%d].testPatch (apply): has conflict: %s", pr.ID, stderr)
|
||||||
const prefix = "error: patch failed:"
|
const prefix = "error: patch failed:"
|
||||||
pr.Status = PullRequestStatusConflict
|
pr.Status = PullRequestStatusConflict
|
||||||
pr.ConflictedFiles = make([]string, 0, 5)
|
pr.ConflictedFiles = make([]string, 0, 5)
|
||||||
|
@ -661,14 +661,17 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
|
||||||
}
|
}
|
||||||
|
|
||||||
pr.Index = pull.Index
|
pr.Index = pull.Index
|
||||||
|
pr.BaseRepo = repo
|
||||||
|
pr.Status = PullRequestStatusChecking
|
||||||
|
if len(patch) > 0 {
|
||||||
if err = repo.savePatch(sess, pr.Index, patch); err != nil {
|
if err = repo.savePatch(sess, pr.Index, patch); err != nil {
|
||||||
return fmt.Errorf("SavePatch: %v", err)
|
return fmt.Errorf("SavePatch: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pr.BaseRepo = repo
|
|
||||||
if err = pr.testPatch(sess); err != nil {
|
if err = pr.testPatch(sess); err != nil {
|
||||||
return fmt.Errorf("testPatch: %v", err)
|
return fmt.Errorf("testPatch: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// No conflict appears after test means mergeable.
|
// No conflict appears after test means mergeable.
|
||||||
if pr.Status == PullRequestStatusChecking {
|
if pr.Status == PullRequestStatusChecking {
|
||||||
pr.Status = PullRequestStatusMergeable
|
pr.Status = PullRequestStatusMergeable
|
||||||
|
|
Reference in a new issue