diff options
author | a1012112796 <1012112796@qq.com> | 2021-04-02 07:57:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-01 19:57:05 -0400 |
commit | c6eb9b30ae202df3ac54b0d09abc5e0af52e1fa2 (patch) | |
tree | 7b6d61862d38c8e07f11a33ff8fe15f62a3dfa80 | |
parent | f75a9b27b0fe291274e8ccd43d2cf7b88375519a (diff) | |
download | gitea-c6eb9b30ae202df3ac54b0d09abc5e0af52e1fa2.tar.gz gitea-c6eb9b30ae202df3ac54b0d09abc5e0af52e1fa2.zip |
response 404 for diff/patch of a commit that not exist (#15221) (#15237)
* 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 6faad1c3c0..5da53568e5 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 c3ee6b5acc..bb98ab60ae 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -6,6 +6,7 @@ package repo import ( + "errors" "path" "strings" @@ -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 } |