Commit 31987259e4c1d878bb796d07e5594156dbcfac5c

Authored by Dmitriy Zaporozhets
1 parent f297c6b3

Fix markdown renderer

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing 1 changed file with 11 additions and 3 deletions   Show diff stats
app/helpers/gitlab_markdown_helper.rb
... ... @@ -166,14 +166,14 @@ module GitlabMarkdownHelper
166 166  
167 167 def file_exists?(path)
168 168 return false if path.nil? || path.empty?
169   - return @repository.blob_at(current_ref, path).present? || @repository.tree(:head, path).entries.any?
  169 + return @repository.blob_at(current_sha, path).present? || @repository.tree(current_sha, path).entries.any?
170 170 end
171 171  
172 172 # Check if the path is pointing to a directory(tree) or a file(blob)
173 173 # eg. doc/api is directory and doc/README.md is file
174 174 def local_path(path)
175   - return "tree" if @repository.tree(:head, path).entries.any?
176   - return "raw" if @repository.blob_at(current_ref, path).image?
  175 + return "tree" if @repository.tree(current_sha, path).entries.any?
  176 + return "raw" if @repository.blob_at(current_sha, path).image?
177 177 return "blob"
178 178 end
179 179  
... ... @@ -181,6 +181,14 @@ module GitlabMarkdownHelper
181 181 @commit.nil? ? "master" : @commit.id
182 182 end
183 183  
  184 + def current_sha
  185 + if @commit
  186 + @commit.id
  187 + else
  188 + @repository.head_commit.sha
  189 + end
  190 + end
  191 +
184 192 # We will assume that if no ref exists we can point to master
185 193 def correct_ref(ref)
186 194 ref ? ref : "master"
... ...