summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-07-24 20:18:14 +0000
committerValery Sizov <valery@gitlab.com>2015-07-24 20:18:14 +0000
commitbbbcc9657f60960fadae2d9bbd1a11b3a5319e1f (patch)
tree77f1dde8160b43e6a2e6f1b658f5bd86948b70cf
parent330109ee4142f5eca53ff536828626694f4e7db8 (diff)
parenta5e8ea54eceeb02fe34f0265d8cfe6af8b599098 (diff)
downloadgitlab-ce-bbbcc9657f60960fadae2d9bbd1a11b3a5319e1f.tar.gz
Merge branch 'fix-error-500-when-no-head' into 'master'
Fix error 500 when no HEAD is available Steps to reproduce: 1. Create a project with a README 2. In the actual remote, type: `git symbolic-ref HEAD refs/heads/nowhere` 3. Check that HEAD is gone via `git ls-remote .` 4. Go to the projects page and see the Error 500 Error: ``` NoMethodError - undefined method `sha' for nil:NilClass: app/helpers/projects_helper.rb:281:in `readme_cache_key' app/views/projects/_readme.html.haml:10:in `_app_views_projects__readme_html_haml___2036282917939462960_70154565285700' actionview (4.1.11) lib/action_view/template.rb:145:in `block in render' activesupport (4.1.11) lib/active_support/notifications.rb:159:in `block in instrument' activesupport (4.1.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (4.1.11) lib/active_support/notifications.rb:159:in `instrument' actionview (4.1.11) lib/action_view/template.rb:339:in `instrument' actionview (4.1.11) lib/action_view/template.rb:143:in `render' rack-mini-profiler (0.9.0) lib/mini_profiler/profiling_methods.rb:108:in `block in profile_method' actionview (4.1.11) lib/action_view/renderer/partial_renderer.rb:306:in `render_partial' actionview (4.1.11) lib/action_view/renderer/partial_renderer.rb:279:in `block in render' actionview (4.1.11) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument' activesupport (4.1.11) lib/active_support/notifications.rb:159:in `block in instrument' activesupport (4.1.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (4.1.11) lib/active_support/notifications.rb:159:in `instrument' actionview (4.1.11) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument' actionview (4.1.11) lib/action_view/renderer/partial_renderer.rb:278:in `render' actionview (4.1.11) lib/action_view/renderer/renderer.rb:47:in `render_partial' actionview (4.1.11) lib/action_view/helpers/rendering_helper.rb:35:in `render' haml (4.0.5) lib/haml/helpers/action_view_mods.rb:10:in `block in render_with_haml' haml (4.0.5) lib/haml/helpers.rb:89:in `non_haml' haml (4.0.5) lib/haml/helpers/action_view_mods.rb:10:in `render_with_haml' app/views/projects/show.html.haml:47:in `_app_views_projects_show_html_haml__1458303859692972698_70154948164180' actionview (4.1.11) lib/action_view/template.rb:145:in `block in render' activesupport (4.1.11) lib/active_support/notifications.rb:159:in `block in instrument' ``` Closes https://github.com/gitlabhq/gitlabhq/issues/9484, but there may be some other issue there. See merge request !1041
-rw-r--r--CHANGELOG1
-rw-r--r--app/helpers/projects_helper.rb3
-rw-r--r--spec/helpers/projects_helper_spec.rb20
3 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 9ffbf64fe1d..68fe893e645 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased)
+ - Fix Error 500 when browsing projects with no HEAD (Stan Hu)
- Fix full screen mode for snippet comments (Daniel Gerhardt)
- Fix 404 error in files view after deleting the last file in a repository (Stan Hu)
- Fix label read access for unauthenticated users (Daniel Gerhardt)
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 3cd52b381bd..a675a292432 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -278,7 +278,8 @@ module ProjectsHelper
end
def readme_cache_key
- [@project.id, @project.commit.sha, "readme"].join('-')
+ sha = @project.commit.try(:sha) || 'nil'
+ [@project.id, sha, "readme"].join('-')
end
def round_commit_count(project)
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index beb9b4e438e..99abb95d906 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -22,7 +22,7 @@ describe ProjectsHelper do
let(:user) { create(:user) }
- it "returns false if there are no approipriate permissions" do
+ it "returns false if there are no appropriate permissions" do
allow(helper).to receive(:can?) { false }
expect(helper.can_change_visibility_level?(project, user)).to be_falsey
@@ -52,4 +52,22 @@ describe ProjectsHelper do
end
end
end
+
+ describe "readme_cache_key" do
+ let(:project) { create(:project) }
+
+ before do
+ helper.instance_variable_set(:@project, project)
+ end
+
+ it "returns a valid cach key" do
+ expect(helper.send(:readme_cache_key)).to eq("#{project.id}-#{project.commit.id}-readme")
+ end
+
+ it "returns a valid cache key if HEAD does not exist" do
+ allow(project).to receive(:commit) { nil }
+
+ expect(helper.send(:readme_cache_key)).to eq("#{project.id}-nil-readme")
+ end
+ end
end