Commit 8f9c01feed31c8a87bfbaf89727cd6626ca73db9
Exists in
master
and in
4 other branches
Merge pull request #2946 from Asquera/fix/access_to_non_existent_branch
API: Fixes return code when accessing non existent branch (#2922)
Showing
3 changed files
with
9 additions
and
0 deletions
Show diff stats
doc/api/repositories.md
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 | ... | ... |