diff options
Diffstat (limited to 'modules/git/repo.go')
-rw-r--r-- | modules/git/repo.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go index bf28288448..644ff09284 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -255,7 +255,31 @@ func Push(repoPath string, opts PushOptions) error { cmd.AddArguments("-f") } cmd.AddArguments("--", opts.Remote, opts.Branch) - _, err := cmd.RunInDirWithEnv(repoPath, opts.Env) + var outbuf, errbuf strings.Builder + + err := cmd.RunInDirTimeoutEnvPipeline(opts.Env, -1, repoPath, &outbuf, &errbuf) + if err != nil { + if strings.Contains(errbuf.String(), "non-fast-forward") { + return &ErrPushOutOfDate{ + StdOut: outbuf.String(), + StdErr: errbuf.String(), + Err: err, + } + } else if strings.Contains(errbuf.String(), "! [remote rejected]") { + err := &ErrPushRejected{ + StdOut: outbuf.String(), + StdErr: errbuf.String(), + Err: err, + } + err.GenerateMessage() + return err + } + } + + if errbuf.Len() > 0 && err != nil { + return fmt.Errorf("%v - %s", err, errbuf.String()) + } + return err } |