Commit 8f9c01feed31c8a87bfbaf89727cd6626ca73db9

Authored by Dmitriy Zaporozhets
2 parents 452adb7b 2bd95596

Merge pull request #2946 from Asquera/fix/access_to_non_existent_branch

API: Fixes return code when accessing non existent branch (#2922)
doc/api/repositories.md
... ... @@ -79,6 +79,9 @@ Parameters:
79 79 }
80 80 ```
81 81  
  82 +Will return status code `200` on success or `404 Not found` if the branch is not available.
  83 +
  84 +
82 85 ## Protect a project repository branch
83 86  
84 87 Protect a single project repository branch.
... ...
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 + not_found!("Branch does not exist") 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
... ...