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
@@ -79,6 +79,9 @@ Parameters: | @@ -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 | ## Protect a project repository branch | 85 | ## Protect a project repository branch |
83 | 86 | ||
84 | Protect a single project repository branch. | 87 | Protect a single project repository branch. |
lib/api/projects.rb
@@ -230,6 +230,7 @@ module Gitlab | @@ -230,6 +230,7 @@ module Gitlab | ||
230 | # GET /projects/:id/repository/branches/:branch | 230 | # GET /projects/:id/repository/branches/:branch |
231 | get ":id/repository/branches/:branch" do | 231 | get ":id/repository/branches/:branch" do |
232 | @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } | 232 | @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } |
233 | + not_found!("Branch does not exist") if @branch.nil? | ||
233 | present @branch, with: Entities::RepoObject, project: user_project | 234 | present @branch, with: Entities::RepoObject, project: user_project |
234 | end | 235 | end |
235 | 236 |
spec/requests/api/projects_spec.rb
@@ -109,6 +109,11 @@ describe Gitlab::API do | @@ -109,6 +109,11 @@ describe Gitlab::API do | ||
109 | json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1' | 109 | json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1' |
110 | json_response['protected'].should == false | 110 | json_response['protected'].should == false |
111 | end | 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 | end | 117 | end |
113 | 118 | ||
114 | describe "PUT /projects/:id/repository/branches/:branch/protect" do | 119 | describe "PUT /projects/:id/repository/branches/:branch/protect" do |