diff options
author | zeripath <art27@cantab.net> | 2020-06-08 19:07:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-08 19:07:41 +0100 |
commit | 09f7d84f4cbbfdf81caec922638d8fec4cb7dfca (patch) | |
tree | bb253c991c0d34519d7fbcb5cf0e887110c810c2 /services/pull | |
parent | 5814079bf5fd2369f8720a94128533bad21d1b17 (diff) | |
download | gitea-09f7d84f4cbbfdf81caec922638d8fec4cb7dfca.tar.gz gitea-09f7d84f4cbbfdf81caec922638d8fec4cb7dfca.zip |
Ensure rejected push to refs/pull/index/head fails nicely (#11724)
A pre-receive hook that rejects pushes to refs/pull/index/head
will cause a broken PR which causes an internal server error
whenever it is viewed. This PR handles prevents the internal server
error by handling non-existent pr heads and sends a flash error
informing the creator there was a problem.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/pull')
-rw-r--r-- | services/pull/pull.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/services/pull/pull.go b/services/pull/pull.go index c051641a5b..e8912e47c6 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -443,6 +443,16 @@ func PushToBaseRepo(pr *models.PullRequest) (err error) { // Use InternalPushingEnvironment here because we know that pre-receive and post-receive do not run on a refs/pulls/... Env: models.InternalPushingEnvironment(pr.Issue.Poster, pr.BaseRepo), }); err != nil { + if git.IsErrPushOutOfDate(err) { + // This should not happen as we're using force! + log.Error("Unable to push PR head for %s#%d (%-v:%s) due to ErrPushOfDate: %v", pr.BaseRepo.FullName(), pr.Index, pr.BaseRepo, headFile, err) + return err + } else if git.IsErrPushRejected(err) { + rejectErr := err.(*git.ErrPushRejected) + log.Info("Unable to push PR head for %s#%d (%-v:%s) due to rejection:\nStdout: %s\nStderr: %s\nError: %v", pr.BaseRepo.FullName(), pr.Index, pr.BaseRepo, headFile, rejectErr.StdOut, rejectErr.StdErr, rejectErr.Err) + return err + } + log.Error("Unable to push PR head for %s#%d (%-v:%s) due to Error: %v", pr.BaseRepo.FullName(), pr.Index, pr.BaseRepo, headFile, err) return fmt.Errorf("Push: %s:%s %s:%s %v", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), headFile, err) } |