From 40e7846f3e25b7f679c9dda719c135fca1ef3d5b Mon Sep 17 00:00:00 2001 From: Sebastian Ziebell <sebastian.ziebell@asquera.de> Date: Fri, 8 Feb 2013 17:04:08 +0100 Subject: [PATCH] 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. --- lib/api/projects.rb | 1 + spec/requests/api/projects_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/api/projects.rb b/lib/api/projects.rb index a16243aa822..5e4c564c14b 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -230,6 +230,7 @@ module Gitlab # GET /projects/:id/repository/branches/:branch get ":id/repository/branches/:branch" do @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } + error!("Branch does not exist", 404) if @branch.nil? present @branch, with: Entities::RepoObject, project: user_project end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index d932fd9e74d..16fd1b9307c 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -109,6 +109,11 @@ describe Gitlab::API do json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1' json_response['protected'].should == false 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 describe "PUT /projects/:id/repository/branches/:branch/protect" do -- 2.30.9