Commit bd2ca33d5827401a5ef380ddf323cff86ab38439

Authored by Dmitriy Zaporozhets
2 parents 99334d4b 4e9284a0

Merge branch 'relative' of /home/git/repositories/gitlab/gitlabhq

app/helpers/gitlab_markdown_helper.rb
... ... @@ -64,7 +64,9 @@ module GitlabMarkdownHelper
64 64 # ref - name of the branch or reference, eg. stable
65 65 # requested_path - path of request, eg. doc/api/README.md, used in special case when path is pointing to the .md file were the original request is coming from
66 66 # wiki - whether the markdown is from wiki or not
67   - def create_relative_links(text, project_path_with_namespace, ref, requested_path, wiki = false)
  67 + def create_relative_links(text, project, ref, requested_path, wiki = false)
  68 + @path_to_satellite = project.satellite.path
  69 + project_path_with_namespace = project.path_with_namespace
68 70 paths = extract_paths(text)
69 71 paths.each do |file_path|
70 72 new_path = rebuild_path(project_path_with_namespace, file_path, requested_path, ref)
... ... @@ -145,13 +147,18 @@ module GitlabMarkdownHelper
145 147  
146 148 def file_exists?(path)
147 149 return false if path.nil? || path.empty?
148   - File.exists?(Rails.root.join(path))
  150 + File.exists?(path_on_fs(path))
149 151 end
150 152  
151 153 # Check if the path is pointing to a directory(tree) or a file(blob)
152 154 # eg. doc/api is directory and doc/README.md is file
153 155 def local_path(path)
154   - File.directory?(Rails.root.join(path)) ? "tree" : "blob"
  156 + File.directory?(path_on_fs(path)) ? "tree" : "blob"
  157 + end
  158 +
  159 + # Path to the file in the satellites repository on the filesystem
  160 + def path_on_fs(path)
  161 + [@path_to_satellite, path].join("/")
155 162 end
156 163  
157 164 # We will assume that if no ref exists we can point to master
... ...
lib/redcarpet/render/gitlab_html.rb
... ... @@ -36,7 +36,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
36 36  
37 37 def preprocess(full_document)
38 38 if @project
39   - h.create_relative_links(full_document, @project.path_with_namespace, @ref, @request_path, is_wiki?)
  39 + h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?)
40 40 else
41 41 full_document
42 42 end
... ...
spec/factories.rb
... ... @@ -66,6 +66,7 @@ FactoryGirl.define do
66 66  
67 67 after :create do |project|
68 68 TestEnv.clear_repo_dir(project.namespace, project.path)
  69 + TestEnv.reset_satellite_dir
69 70 TestEnv.create_repo(project.namespace, project.path)
70 71 end
71 72 end
... ...
spec/support/test_env.rb
... ... @@ -97,6 +97,15 @@ module TestEnv
97 97 FileUtils.rm_rf File.join(testing_path(), "#{name}.wiki.git")
98 98 end
99 99  
  100 + def reset_satellite_dir
  101 + setup_stubs
  102 + FileUtils.cd(seed_satellite_path) do
  103 + `git reset --hard --quiet`
  104 + `git clean -fx`
  105 + `git checkout --quiet origin/master`
  106 + end
  107 + end
  108 +
100 109 # Create a repo and it's satellite
101 110 def create_repo(namespace, name)
102 111 setup_stubs
... ...