Skip to content

Commit

Permalink
Gracefully handle bare repositories on API operations. (go-gitea#1932)
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Keitzel <[email protected]>
  • Loading branch information
cybe authored and appleboy committed Jun 11, 2017
1 parent f2fcd9d commit 96b4780
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion models/repo_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
// GetBranch returns a branch by it's name
func (repo *Repository) GetBranch(branch string) (*Branch, error) {
if !git.IsBranchExist(repo.RepoPath(), branch) {
return nil, &ErrBranchNotExist{branch}
return nil, ErrBranchNotExist{branch}
}
return &Branch{
Path: repo.RepoPath(),
Expand Down
7 changes: 6 additions & 1 deletion routers/api/v1/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package repo
import (
api "code.gitea.io/sdk/gitea"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/routers/api/v1/convert"
)
Expand All @@ -16,7 +17,11 @@ import (
func GetBranch(ctx *context.APIContext) {
branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
if err != nil {
ctx.Error(500, "GetBranch", err)
if models.IsErrBranchNotExist(err) {
ctx.Error(404, "GetBranch", err)
} else {
ctx.Error(500, "GetBranch", err)
}
return
}

Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/repo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func GetRawFile(ctx *context.APIContext) {
return
}

if ctx.Repo.Repository.IsBare {
ctx.Status(404)
return
}

blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
Expand Down

0 comments on commit 96b4780

Please sign in to comment.