Skip to content

Commit 0d7afb0

Browse files
a1012112796zeripathsilverwind6543
authored
response 404 for diff/patch of a commit that not exist (#15221) (#15238)
* 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]> Co-authored-by: zeripath <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 1a26f6c commit 0d7afb0

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

@@ -341,6 +342,11 @@ func RawDiff(ctx *context.Context) {
341342
git.RawDiffType(ctx.Params(":ext")),
342343
ctx.Resp,
343344
); err != nil {
345+
if git.IsErrNotExist(err) {
346+
ctx.NotFound("GetRawDiff",
347+
errors.New("commit "+ctx.Params(":sha")+" does not exist."))
348+
return
349+
}
344350
ctx.ServerError("GetRawDiff", err)
345351
return
346352
}

0 commit comments

Comments
 (0)