Commit 631d3e14 authored by Stan Hu's avatar Stan Hu

Merge branch 'fix_no_method_error_when_commit_is_missing' into 'master'

Fix NoMethodError when commit is missing

See merge request gitlab-org/gitlab!79553
parents a90ae8f5 78ae06a4
...@@ -92,6 +92,8 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -92,6 +92,8 @@ class Projects::CommitController < Projects::ApplicationController
end end
def branches def branches
return git_not_found! unless commit
# branch_names_contains/tag_names_contains can take a long time when there are thousands of # branch_names_contains/tag_names_contains can take a long time when there are thousands of
# branches/tags - each `git branch --contains xxx` request can consume a cpu core. # branches/tags - each `git branch --contains xxx` request can consume a cpu core.
# so only do the query when there are a manageable number of branches/tags # so only do the query when there are a manageable number of branches/tags
......
...@@ -183,6 +183,18 @@ RSpec.describe Projects::CommitController do ...@@ -183,6 +183,18 @@ RSpec.describe Projects::CommitController do
expect(assigns(:tags)).to eq([]) expect(assigns(:tags)).to eq([])
expect(assigns(:tags_limit_exceeded)).to be_truthy expect(assigns(:tags_limit_exceeded)).to be_truthy
end end
context 'when commit is not found' do
it 'responds with 404' do
get(:branches, params: {
namespace_id: project.namespace,
project_id: project,
id: '11111111111111111111111111111111111111'
})
expect(response).to be_not_found
end
end
end end
describe 'POST revert' do describe 'POST revert' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment