Commit 53bdcb53ae8891225de6c3b295a8c3f964725b81

Authored by Andrey Kumanyaev
1 parent b75777fd

Fix relative links in markdown. Related to #6182

app/helpers/gitlab_markdown_helper.rb
... ... @@ -166,18 +166,18 @@ module GitlabMarkdownHelper
166 166  
167 167 def file_exists?(path)
168 168 return false if path.nil? || path.empty?
169   - File.exists?(path_on_fs(path))
  169 + return @repository.blob_at(current_ref, path).present? || Tree.new(@repository, current_ref, 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   - File.directory?(path_on_fs(path)) ? "tree" : "blob"
  175 + return "tree" if Tree.new(@repository, current_ref, path).entries.any?
  176 + return "blob"
176 177 end
177 178  
178   - # Path to the file in the satellites repository on the filesystem
179   - def path_on_fs(path)
180   - [@path_to_satellite, path].join("/")
  179 + def current_ref
  180 + @commit.nil? ? "master" : @commit.id
181 181 end
182 182  
183 183 # We will assume that if no ref exists we can point to master
... ...
spec/helpers/gitlab_markdown_helper_spec.rb
... ... @@ -16,6 +16,7 @@ describe GitlabMarkdownHelper do
16 16 before do
17 17 # Helper expects a @project instance variable
18 18 @project = project
  19 + @repository = project.repository
19 20 end
20 21  
21 22 describe "#gfm" do
... ...