Commit 40e7846f3e25b7f679c9dda719c135fca1ef3d5b
1 parent
2f0a75ab
Exists in
master
and in
4 other branches
Status code 404 returned when retrieving non existent branch (issue #2922)
Accessing a repository branch that does not exist returns a 404 error instead of 200 now. Added a test.
Showing
2 changed files
with
6 additions
and
0 deletions
Show diff stats
lib/api/projects.rb
... | ... | @@ -230,6 +230,7 @@ module Gitlab |
230 | 230 | # GET /projects/:id/repository/branches/:branch |
231 | 231 | get ":id/repository/branches/:branch" do |
232 | 232 | @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } |
233 | + error!("Branch does not exist", 404) if @branch.nil? | |
233 | 234 | present @branch, with: Entities::RepoObject, project: user_project |
234 | 235 | end |
235 | 236 | ... | ... |
spec/requests/api/projects_spec.rb
... | ... | @@ -109,6 +109,11 @@ describe Gitlab::API do |
109 | 109 | json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1' |
110 | 110 | json_response['protected'].should == false |
111 | 111 | end |
112 | + | |
113 | + it "should return a 404 error if branch is not available" do | |
114 | + get api("/projects/#{project.id}/repository/branches/unknown", user) | |
115 | + response.status.should == 404 | |
116 | + end | |
112 | 117 | end |
113 | 118 | |
114 | 119 | describe "PUT /projects/:id/repository/branches/:branch/protect" do | ... | ... |