提交 8f9c01fe 编写于 作者: D Dmitriy Zaporozhets

Merge pull request #2946 from Asquera/fix/access_to_non_existent_branch

API: Fixes return code when accessing non existent branch (#2922)
...@@ -79,6 +79,9 @@ Parameters: ...@@ -79,6 +79,9 @@ Parameters:
} }
``` ```
Will return status code `200` on success or `404 Not found` if the branch is not available.
## Protect a project repository branch ## Protect a project repository branch
Protect a single project repository branch. Protect a single project repository branch.
......
...@@ -230,6 +230,7 @@ module Gitlab ...@@ -230,6 +230,7 @@ module Gitlab
# GET /projects/:id/repository/branches/:branch # GET /projects/:id/repository/branches/:branch
get ":id/repository/branches/:branch" do get ":id/repository/branches/:branch" do
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] } @branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
not_found!("Branch does not exist") if @branch.nil?
present @branch, with: Entities::RepoObject, project: user_project present @branch, with: Entities::RepoObject, project: user_project
end end
......
...@@ -109,6 +109,11 @@ describe Gitlab::API do ...@@ -109,6 +109,11 @@ describe Gitlab::API do
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1' json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['protected'].should == false json_response['protected'].should == false
end end
it "should return a 404 error if branch is not available" do
get api("/projects/#{project.id}/repository/branches/unknown", user)
response.status.should == 404
end
end end
describe "PUT /projects/:id/repository/branches/:branch/protect" do describe "PUT /projects/:id/repository/branches/:branch/protect" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册