diff options
author | zeripath <art27@cantab.net> | 2020-03-28 04:13:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 01:13:18 -0300 |
commit | 7cd47046ea6e1fde2c88290a42f345795aee0ea4 (patch) | |
tree | 6004084e3c478a68a47b47deb0143a2b142fb821 /modules/git/repo.go | |
parent | cac30abefc02e36ed08810b7101b4f6a7c8bb599 (diff) | |
download | gitea-7cd47046ea6e1fde2c88290a42f345795aee0ea4.tar.gz gitea-7cd47046ea6e1fde2c88290a42f345795aee0ea4.zip |
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 <art27@cantab.net>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
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 } |