Skip to content

Commit

Permalink
response 404 for diff/patch of a commit that not exist (go-gitea#15221)
Browse files Browse the repository at this point in the history
* response 404 for diff/patch of a commit that not exist

fix go-gitea#15217

Signed-off-by: a1012112796 <1012112796@qq.com>

* Update routers/repo/commit.go

Co-authored-by: silverwind <me@silverwind.io>

* use ctx.NotFound()

Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: silverwind <me@silverwind.io>
  • Loading branch information
3 people committed Apr 1, 2021
1 parent 2b68f66 commit 31f387d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/git/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func GetRawDiffForFile(repoPath, startCommit, endCommit string, diffType RawDiff
func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
commit, err := repo.GetCommit(endCommit)
if err != nil {
return fmt.Errorf("GetCommit: %v", err)
return err
}
fileArgs := make([]string, 0)
if len(file) > 0 {
Expand Down
6 changes: 6 additions & 0 deletions routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package repo

import (
"errors"
"path"
"strings"

Expand Down Expand Up @@ -389,6 +390,11 @@ func RawDiff(ctx *context.Context) {
git.RawDiffType(ctx.Params(":ext")),
ctx.Resp,
); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("GetRawDiff",
errors.New("commit "+ctx.Params(":sha")+" does not exist."))
return
}
ctx.ServerError("GetRawDiff", err)
return
}
Expand Down

0 comments on commit 31f387d

Please sign in to comment.