Error 500 when anonymous user attempts to view a public, empty project that has disabled the repository feature
Created by @stanhu. From gitlab-com/support-forum#1279.
It looks like ProjectsController#render_landing_page
isn't handling the case where:
- Project has disabled repository feature
- User is anonymous
- Project is empty
The Error 500 is occurring because the render_landing_page
is calling render :show
down at the end, which can't get the HEAD commit to display the README.
def render_landing_page
if @project.feature_available?(:repository, current_user)
return render 'projects/no_repo' unless @project.repository_exists?
render 'projects/empty' if @project.empty_repo?
else
if @project.wiki_enabled?
@project_wiki = @project.wiki
@wiki_home = @project_wiki.find_page('home', params[:version_id])
elsif @project.feature_available?(:issues, current_user)
@issues = issues_collection
@issues = @issues.page(params[:page])
end
render :show
end
end
https://sentry.gitlap.com/gitlab/gitlabcom/issues/14662/
NoMethodError: undefined method `sha' for nil:NilClass
app/models/repository.rb:671:in `head_tree'
@head_tree ||= Tree.new(self, head_commit.sha, nil)
lib/gitlab/metrics/instrumentation.rb:155:in `block in head_tree'
trans.method_call_for(#{label.to_sym.inspect}).measure { super }
lib/gitlab/metrics/method_call.rb:23:in `measure'
retval = yield
lib/gitlab/metrics/instrumentation.rb:155:in `head_tree'
trans.method_call_for(#{label.to_sym.inspect}).measure { super }
app/models/repository.rb:677:in `tree'
return head_tree
...
(178 additional frame(s) were not displayed)
ActionView::Template::Error: undefined method `sha' for nil:NilClass