summaryrefslogtreecommitdiffstats
path: root/modules/repofiles
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-02-22 13:08:48 +0000
committerGitHub <noreply@github.com>2020-02-22 15:08:48 +0200
commit089ccb0c80050efc8c3afef2402ea4f4a5ed250e (patch)
tree4ff172035ffd0a9a5263dedc051a91ab24c33fa6 /modules/repofiles
parent2ed9ead6dea29f9e006fa1831892c9c239f4bd70 (diff)
downloadgitea-089ccb0c80050efc8c3afef2402ea4f4a5ed250e.tar.gz
gitea-089ccb0c80050efc8c3afef2402ea4f4a5ed250e.zip
Handle push rejection message in Merge & Web Editor (#10373)
* Handle push rejection message in Merge * placate golangci-lint * Fix sanitize, adjust message handling * oops * Oops * Handle push-rejection in webeditor CRUD too * Apply suggestions from code review Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/repofiles')
-rw-r--r--modules/repofiles/temp_repo.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/modules/repofiles/temp_repo.go b/modules/repofiles/temp_repo.go
index f7e3935c25..d8b816dfa1 100644
--- a/modules/repofiles/temp_repo.go
+++ b/modules/repofiles/temp_repo.go
@@ -242,8 +242,28 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
func (t *TemporaryUploadRepository) Push(doer *models.User, commitHash string, branch string) error {
// Because calls hooks we need to pass in the environment
env := models.PushingEnvironment(doer, t.repo)
-
- if stdout, err := git.NewCommand("push", t.repo.RepoPath(), strings.TrimSpace(commitHash)+":refs/heads/"+strings.TrimSpace(branch)).RunInDirWithEnv(t.basePath, env); err != nil {
+ stdout := &strings.Builder{}
+ stderr := &strings.Builder{}
+
+ if err := git.NewCommand("push", t.repo.RepoPath(), strings.TrimSpace(commitHash)+":refs/heads/"+strings.TrimSpace(branch)).RunInDirTimeoutEnvPipeline(env, -1, t.basePath, stdout, stderr); err != nil {
+ errString := stderr.String()
+ if strings.Contains(errString, "non-fast-forward") {
+ return models.ErrMergePushOutOfDate{
+ StdOut: stdout.String(),
+ StdErr: errString,
+ Err: err,
+ }
+ } else if strings.Contains(errString, "! [remote rejected]") {
+ log.Error("Unable to push back to repo from temporary repo due to rejection: %s (%s)\nStdout: %s\nStderr: %s\nError: %v",
+ t.repo.FullName(), t.basePath, stdout, errString, err)
+ err := models.ErrPushRejected{
+ StdOut: stdout.String(),
+ StdErr: errString,
+ Err: err,
+ }
+ err.GenerateMessage()
+ return err
+ }
log.Error("Unable to push back to repo from temporary repo: %s (%s)\nStdout: %s\nError: %v",
t.repo.FullName(), t.basePath, stdout, err)
return fmt.Errorf("Unable to push back to repo from temporary repo: %s (%s) Error: %v",