summaryrefslogtreecommitdiffstats
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-11-10 08:42:51 +0000
committerGitHub <noreply@github.com>2019-11-10 08:42:51 +0000
commit8eeb2877d5803d0501815466d651a519b32bbd3a (patch)
treeffd1abc59788797e0d99169b8a88655f51d4128f /routers/repo/pull.go
parent31416a5f4e70d4972c351cde170b59d13fcbb77f (diff)
downloadgitea-8eeb2877d5803d0501815466d651a519b32bbd3a.tar.gz
gitea-8eeb2877d5803d0501815466d651a519b32bbd3a.zip
Adjust error reporting from merge failures and use LC_ALL=C for git (#8548)
There are two major components to this PR: * This PR handles merge and rebase failures from merging a little more nicely with Flash errors rather a 500. * All git commands are run in the LC_ALL="C" environment to ensure that error messages are in English. This DefaultLocale is defined in a way that if necessary (due to platform weirdness) it can be overridden at build time using LDFLAGS="-X "code.gitea.io/gitea/modules/git.DefaultLocale=C"" with C changed for the locale as necessary.
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index cb9c7c1164..0eea5fcbe6 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -10,6 +10,7 @@ import (
"container/list"
"crypto/subtle"
"fmt"
+ "html"
"io"
"path"
"strings"
@@ -660,10 +661,39 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
}
if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
+ sanitize := func(x string) string {
+ runes := []rune(x)
+
+ if len(runes) > 512 {
+ x = "..." + string(runes[len(runes)-512:])
+ }
+
+ return strings.Replace(html.EscapeString(x), "\n", "<br>", -1)
+ }
if models.IsErrInvalidMergeStyle(err) {
ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
return
+ } else if models.IsErrMergeConflicts(err) {
+ conflictError := err.(models.ErrMergeConflicts)
+ ctx.Flash.Error(ctx.Tr("repo.pulls.merge_conflict", sanitize(conflictError.StdErr), sanitize(conflictError.StdOut)))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
+ } else if models.IsErrRebaseConflicts(err) {
+ conflictError := err.(models.ErrRebaseConflicts)
+ ctx.Flash.Error(ctx.Tr("repo.pulls.rebase_conflict", sanitize(conflictError.CommitSHA), sanitize(conflictError.StdErr), sanitize(conflictError.StdOut)))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
+ } else if models.IsErrMergeUnrelatedHistories(err) {
+ log.Debug("MergeUnrelatedHistories error: %v", err)
+ ctx.Flash.Error(ctx.Tr("repo.pulls.unrelated_histories"))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
+ } else if models.IsErrMergePushOutOfDate(err) {
+ log.Debug("MergePushOutOfDate error: %v", err)
+ ctx.Flash.Error(ctx.Tr("repo.pulls.merge_out_of_date"))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
}
ctx.ServerError("Merge", err)
return