Error 500 when using Markdown code block with empty repository

Created by: Anthony-Gaudino

This error was reproduced on Master and 1.9.1 following this:

  1. Create a new project on GitLab
  2. Create a issue, Wiki page or anything containing a code block that will be parsed by Markdown. Ex:
    '''ruby
    require 'redcarpet'
    markdown = Redcarpet.new("Hello World!")
    puts markdown.to_html
    '''
    
    I know the ''' are wrong but its just to skip GitHub's own Markdown
  3. When viewed you get a 500 server error

To solve this issue you must push something to the repository, so Gitolite will create the project folder.

Here's a production.log entry with the error:

Started GET "/lixo/issues/1" for 127.0.0.1 at 2012-09-29 15:10:22 -0300
Processing by IssuesController#show as HTML
  Parameters: {"project_id"=>"lixo", "id"=>"1"}
  Rendered votes/_votes_block.html.haml (3.4ms)
  Rendered issues/show.html.haml within layouts/project (124.9ms)
Completed 500 Internal Server Error in 159ms

ActionView::Template::Error (/var/lib/gitolite/repositories/lixo.git):
    58:   - if @issue.description.present?
    59:     .bottom_box_content
    60:       = preserve do
    61:         = markdown @issue.description
    62: 
    63: 
    64: .issue_notes.voting_notes#notes= render "notes/notes_with_form", tid: @issue.id, tt: "issue"
  app/roles/repository.rb:53:in `new'
  app/roles/repository.rb:53:in `repo'
  app/roles/repository.rb:16:in `commit'
  lib/gitlab/markdown.rb:176:in `reference_commit'
  lib/gitlab/markdown.rb:146:in `reference_link'
  lib/gitlab/markdown.rb:106:in `block in parse_references'
  lib/gitlab/markdown.rb:97:in `gsub!'
  lib/gitlab/markdown.rb:97:in `parse_references'
  lib/gitlab/markdown.rb:89:in `parse'
  lib/gitlab/markdown.rb:69:in `gfm'
  lib/redcarpet/render/gitlab_html.rb:21:in `postprocess'
  app/helpers/gitlab_markdown_helper.rb:44:in `render'
  app/helpers/gitlab_markdown_helper.rb:44:in `markdown'
  app/views/issues/show.html.haml:61:in `block in _app_views_issues_show_html_haml__3635129314219616355_64843040'
  app/views/issues/show.html.haml:60:in `_app_views_issues_show_html_haml__3635129314219616355_64843040'
  app/controllers/issues_controller.rb:51:in `show'