Skip to content

Commit c6eb9b3

Browse files
a1012112796zeripathsilverwind6543
authored
response 404 for diff/patch of a commit that not exist (go-gitea#15221) (go-gitea#15237)
* response 404 for diff/patch of a commit that not exist fix go-gitea#15217 Signed-off-by: a1012112796 <[email protected]> * Update routers/repo/commit.go Co-authored-by: silverwind <[email protected]> * use ctx.NotFound() Co-authored-by: zeripath <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent f75a9b2 commit c6eb9b3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

modules/git/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func GetRawDiffForFile(repoPath, startCommit, endCommit string, diffType RawDiff
4747
func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
4848
commit, err := repo.GetCommit(endCommit)
4949
if err != nil {
50-
return fmt.Errorf("GetCommit: %v", err)
50+
return err
5151
}
5252
fileArgs := make([]string, 0)
5353
if len(file) > 0 {

routers/repo/commit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package repo
77

88
import (
9+
"errors"
910
"path"
1011
"strings"
1112

@@ -389,6 +390,11 @@ func RawDiff(ctx *context.Context) {
389390
git.RawDiffType(ctx.Params(":ext")),
390391
ctx.Resp,
391392
); err != nil {
393+
if git.IsErrNotExist(err) {
394+
ctx.NotFound("GetRawDiff",
395+
errors.New("commit "+ctx.Params(":sha")+" does not exist."))
396+
return
397+
}
392398
ctx.ServerError("GetRawDiff", err)
393399
return
394400
}

0 commit comments

Comments
 (0)