From 7cd47046ea6e1fde2c88290a42f345795aee0ea4 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 28 Mar 2020 04:13:18 +0000 Subject: Handle push rejection in branch and upload (#10854) * Handle push rejections and push out-of-date in branch creation and file upload. * Remove the duplicated sanitize from services/pull/merge * Move the errors Err(Merge)PushOutOfDate and ErrPushRejected to modules/git * Handle errors better in the upload file dialogs Fix #10460 Signed-off-by: Andrew Thornton Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> --- models/error.go | 66 --------------------------------------------------------- 1 file changed, 66 deletions(-) (limited to 'models') diff --git a/models/error.go b/models/error.go index 19a1229ada..a5b62b85ec 100644 --- a/models/error.go +++ b/models/error.go @@ -7,7 +7,6 @@ package models import ( "fmt" - "strings" "code.gitea.io/gitea/modules/git" ) @@ -1388,71 +1387,6 @@ func (err ErrMergeUnrelatedHistories) Error() string { return fmt.Sprintf("Merge UnrelatedHistories Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut) } -// ErrMergePushOutOfDate represents an error if merging fails due to unrelated histories -type ErrMergePushOutOfDate struct { - Style MergeStyle - StdOut string - StdErr string - Err error -} - -// IsErrMergePushOutOfDate checks if an error is a ErrMergePushOutOfDate. -func IsErrMergePushOutOfDate(err error) bool { - _, ok := err.(ErrMergePushOutOfDate) - return ok -} - -func (err ErrMergePushOutOfDate) Error() string { - return fmt.Sprintf("Merge PushOutOfDate Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut) -} - -// ErrPushRejected represents an error if merging fails due to rejection from a hook -type ErrPushRejected struct { - Style MergeStyle - Message string - StdOut string - StdErr string - Err error -} - -// IsErrPushRejected checks if an error is a ErrPushRejected. -func IsErrPushRejected(err error) bool { - _, ok := err.(ErrPushRejected) - return ok -} - -func (err ErrPushRejected) Error() string { - return fmt.Sprintf("Merge PushRejected Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut) -} - -// GenerateMessage generates the remote message from the stderr -func (err *ErrPushRejected) GenerateMessage() { - messageBuilder := &strings.Builder{} - i := strings.Index(err.StdErr, "remote: ") - if i < 0 { - err.Message = "" - return - } - for { - if len(err.StdErr) <= i+8 { - break - } - if err.StdErr[i:i+8] != "remote: " { - break - } - i += 8 - nl := strings.IndexByte(err.StdErr[i:], '\n') - if nl >= 0 { - messageBuilder.WriteString(err.StdErr[i : i+nl+1]) - i = i + nl + 1 - } else { - messageBuilder.WriteString(err.StdErr[i:]) - i = len(err.StdErr) - } - } - err.Message = strings.TrimSpace(messageBuilder.String()) -} - // ErrRebaseConflicts represents an error if rebase fails with a conflict type ErrRebaseConflicts struct { Style MergeStyle -- cgit v1.2.3