diff options
author | a1012112796 | 2021-04-02 11:30:14 +0800 |
---|---|---|
committer | GitHub | 2021-04-02 04:30:14 +0100 |
commit | 0d7afb02c0c354550cb1e45f7057f23d90e03cb6 (patch) | |
tree | bde2ad4f0d973b0a1f2ea938a0565939a6316ded | |
parent | 1a26f6c7abef670be624c38f626acd1dee5c2bfa (diff) |
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 <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>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: 6543 <6543@obermui.de>
-rw-r--r-- | modules/git/diff.go | 2 | ||||
-rw-r--r-- | routers/repo/commit.go | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/modules/git/diff.go b/modules/git/diff.go index 6faad1c3c..5da53568e 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -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 { diff --git a/routers/repo/commit.go b/routers/repo/commit.go index d9547cc51..11329727e 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -6,6 +6,7 @@ package repo import ( + "errors" "path" "strings" @@ -341,6 +342,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 } |