summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/helpers/commits_helper.rb8
-rw-r--r--app/models/project.rb2
-rw-r--r--app/views/commits/_text_file.html.haml2
-rw-r--r--config/routes.rb4
-rw-r--r--lib/extracts_path.rb12
-rw-r--r--spec/lib/extracts_path_spec.rb20
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb1
7 files changed, 44 insertions, 5 deletions
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index 2349888ed7a..8fc637a2bf6 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -70,4 +70,12 @@ module CommitsHelper
escape_javascript(render 'commits/commit', commit: commit)
end
end
+
+ def diff_line_content(line)
+ if line.blank?
+ "  "
+ else
+ line
+ end
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 3e5c912e0b4..c2986707667 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -102,7 +102,7 @@ class Project < ActiveRecord::Base
if id.include?("/")
id = id.split("/")
namespace_id = Namespace.find_by_path(id.first).id
- where(namespace_id: namespace_id).find_by_path(id.last)
+ where(namespace_id: namespace_id).find_by_path(id.second)
else
where(path: id, namespace_id: nil).last
end
diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml
index 02117386d71..ecdae2f3715 100644
--- a/app/views/commits/_text_file.html.haml
+++ b/app/views/commits/_text_file.html.haml
@@ -15,7 +15,7 @@
- if @comments_allowed
= render "notes/per_line_note_link", line_code: line_code
%td.new_line= link_to raw(type == "old" ? "&nbsp;" : line_new) , "##{line_code}", id: line_code
- %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line} &nbsp;"
+ %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line)
- if @comments_allowed
- comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at)
diff --git a/config/routes.rb b/config/routes.rb
index e08bfebc020..51b183688dd 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -112,7 +112,7 @@ Gitlab::Application.routes.draw do
#
# Project Area
#
- resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do
+ resources :projects, constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }, except: [:new, :create, :index], path: "/" do
member do
get "wall"
get "graph"
@@ -190,12 +190,12 @@ Gitlab::Application.routes.draw do
end
end
+ resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/}
resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/}
resources :commits, only: [:show], constraints: {id: /.+/}
resources :compare, only: [:index, :create]
resources :blame, only: [:show], constraints: {id: /.+/}
resources :blob, only: [:show], constraints: {id: /.+/}
- resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/}
match "/compare/:from...:to" => "compare#show", as: "compare",
:via => [:get, :post], constraints: {from: /.+/, to: /.+/}
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index b60dfd036e1..220e3d2271f 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -33,6 +33,9 @@ module ExtractsPath
# extract_ref("v2.0.0/README.md")
# # => ['v2.0.0', 'README.md']
#
+ # extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb')
+ # # => ['master', 'app/models/project.rb']
+ #
# extract_ref('issues/1234/app/models/project.rb')
# # => ['issues/1234', 'app/models/project.rb']
#
@@ -47,6 +50,13 @@ module ExtractsPath
return pair unless @project
+ # Remove project, actions and all other staff from path
+ input.gsub!("/#{@project.path_with_namespace}", "")
+ input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions
+ input.gsub!(/\?.*$/, "") # remove stamps suffix
+ input.gsub!(/.atom$/, "") # remove rss feed
+ input.gsub!(/\/edit$/, "") # remove edit route part
+
if input.match(/^([[:alnum:]]{40})(.+)/)
# If the ref appears to be a SHA, we're done, just split the string
pair = $~.captures
@@ -98,7 +108,7 @@ module ExtractsPath
request.format = :atom
end
- @ref, @path = extract_ref(params[:id])
+ @ref, @path = extract_ref(request.fullpath)
@id = File.join(@ref, @path)
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index cf4220175a7..8773d77f5a5 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -8,6 +8,7 @@ describe ExtractsPath do
before do
@project = project
project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])
+ project.stub(path_with_namespace: 'gitlab/gitlab-ci')
end
describe '#extract_ref' do
@@ -53,5 +54,24 @@ describe ExtractsPath do
extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
end
end
+
+ context "with a fullpath" do
+ it "extracts a valid branch" do
+ extract_ref('/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
+ end
+
+ it "extracts a valid tag" do
+ extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
+ end
+
+ it "extracts a valid commit SHA" do
+ extract_ref('/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
+ ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
+ end
+
+ it "extracts a timestamp" do
+ extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']
+ end
+ end
end
end
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index b17521e0148..babbf2916f8 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -3,6 +3,7 @@ require 'rake'
describe 'gitlab:app namespace rake task' do
before :all do
+ Rake.application.rake_require "tasks/gitlab/task_helpers"
Rake.application.rake_require "tasks/gitlab/backup"
# empty task as env is already loaded
Rake::Task.define_task :environment