Skip to content

Commit 007fb00

Browse files
a1012112796zeripathsilverwind
authored
response 404 for diff/patch of a commit that not exist (#15221)
* response 404 for diff/patch of a commit that not exist fix #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]>
1 parent f07b137 commit 007fb00

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

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

0 commit comments

Comments
 (0)