From 53bdcb53ae8891225de6c3b295a8c3f964725b81 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 29 Jan 2014 17:48:59 +0400 Subject: [PATCH] Fix relative links in markdown. Related to #6182 --- app/helpers/gitlab_markdown_helper.rb | 10 +++++----- spec/helpers/gitlab_markdown_helper_spec.rb | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 60f9d4e76..dd7d3272c 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -166,18 +166,18 @@ module GitlabMarkdownHelper def file_exists?(path) return false if path.nil? || path.empty? - File.exists?(path_on_fs(path)) + return @repository.blob_at(current_ref, path).present? || Tree.new(@repository, current_ref, path).entries.any? end # Check if the path is pointing to a directory(tree) or a file(blob) # eg. doc/api is directory and doc/README.md is file def local_path(path) - File.directory?(path_on_fs(path)) ? "tree" : "blob" + return "tree" if Tree.new(@repository, current_ref, path).entries.any? + return "blob" end - # Path to the file in the satellites repository on the filesystem - def path_on_fs(path) - [@path_to_satellite, path].join("/") + def current_ref + @commit.nil? ? "master" : @commit.id end # We will assume that if no ref exists we can point to master diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 427ac0f80..59abfb38e 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -16,6 +16,7 @@ describe GitlabMarkdownHelper do before do # Helper expects a @project instance variable @project = project + @repository = project.repository end describe "#gfm" do -- 2.11.0