summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2019-06-10 11:26:25 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2019-06-10 11:26:25 +0000
commit3f101f8b077f714ac5495fd95d52fe84f6892edc (patch)
treed1d6484d23ef7d935d25bcb88a8b259dc4105b59
parentbd8d4feed0a995f450a675d6bbf02de9af300bef (diff)
downloadredmine-3f101f8b077f714ac5495fd95d52fe84f6892edc.tar.gz
redmine-3f101f8b077f714ac5495fd95d52fe84f6892edc.zip
Merged r17962, r18206, r18207 and r18211 to 4.0-stable (#30850).
git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@18242 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/repositories_controller.rb3
-rw-r--r--config/routes.rb13
-rw-r--r--test/integration/repositories_git_test.rb58
-rw-r--r--test/integration/routing/repositories_test.rb18
4 files changed, 85 insertions, 7 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 346ecf5c7..c467def29 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -255,12 +255,13 @@ class RepositoriesController < ApplicationController
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
unless read_fragment(@cache_key)
@diff = @repository.diff(@path, @rev, @rev_to)
- show_error_not_found unless @diff
+ (show_error_not_found; return) unless @diff
end
@changeset = @repository.find_changeset_by_name(@rev)
@changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
@diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
+ render :diff, :formats => :html
end
end
diff --git a/config/routes.rb b/config/routes.rb
index 034498208..be9838aea 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -246,7 +246,7 @@ Rails.application.routes.draw do
post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue'
delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions'
- %w(browse show entry raw annotate diff).each do |action|
+ %w(browse show entry raw annotate).each do |action|
get "projects/:id/repository/:repository_id/revisions/:rev/#{action}(/*path)",
:controller => 'repositories',
:action => action,
@@ -254,7 +254,7 @@ Rails.application.routes.draw do
:constraints => {:rev => /[a-z0-9\.\-_]+/, :path => /.*/}
end
- %w(browse entry raw changes annotate diff).each do |action|
+ %w(browse entry raw changes annotate).each do |action|
get "projects/:id/repository/:repository_id/#{action}(/*path)",
:controller => 'repositories',
:action => action,
@@ -262,6 +262,15 @@ Rails.application.routes.draw do
:constraints => {:path => /.*/}
end
+ get "projects/:id/repository/:repository_id/revisions/:rev/diff(/*path)",
+ :to => 'repositories#diff',
+ :format => false,
+ :constraints => {:rev => /[a-z0-9\.\-_]+/, :path => /.*/}
+ get "projects/:id/repository/:repository_id/diff(/*path)",
+ :to => 'repositories#diff',
+ :format => false,
+ :constraints => {:path => /.*/}
+
get 'projects/:id/repository/:repository_id/show/*path', :to => 'repositories#show', :format => 'html', :constraints => {:path => /.*/}
get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
diff --git a/test/integration/repositories_git_test.rb b/test/integration/repositories_git_test.rb
index ba1922240..b436d0e5c 100644
--- a/test/integration/repositories_git_test.rb
+++ b/test/integration/repositories_git_test.rb
@@ -24,6 +24,7 @@ class RepositoriesGitTest < Redmine::IntegrationTest
REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
PRJ_ID = 3
+ NUM_REV = 28
def setup
User.current = nil
@@ -46,5 +47,62 @@ class RepositoriesGitTest < Redmine::IntegrationTest
get "/projects/subproject1/repository/#{@repository.id}/diff?rev=61b685fbe&rev_to=2f9c0091"
assert_response :success
end
+
+ def test_get_raw_diff_of_a_whole_revision
+ @repository.fetch_changesets
+ assert_equal NUM_REV, @repository.changesets.count
+
+ get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff"
+ assert_response :success
+
+ assert a = css_select("a.diff").first
+ assert_equal 'Unified diff', a.text
+ get a['href']
+ assert_response :success
+ assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
+ end
+
+ def test_get_raw_diff_of_a_single_file_change
+ @repository.fetch_changesets
+ assert_equal NUM_REV, @repository.changesets.count
+
+ get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff/sources/watchers_controller.rb"
+ assert_response :success
+
+ assert a = css_select("a.diff").first
+ assert_equal 'Unified diff', a.text
+ get a['href']
+ assert_response :success
+ assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
+ end
+
+ def test_get_diff_with_format_text_should_return_html
+ @repository.fetch_changesets
+ assert_equal NUM_REV, @repository.changesets.count
+
+ get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/diff/sources/watchers_controller.rb", :params => { :format => 'txt' }
+ assert_response :success
+
+ assert a = css_select("a.diff").first
+ assert_equal 'Unified diff', a.text
+ get a['href']
+ assert_response :success
+ assert_match /\Acommit deff712f05a90d96edbd70facc47d944be5897e3/, response.body
+ end
+
+ def test_entry_txt_should_return_html
+ @repository.fetch_changesets
+ assert_equal NUM_REV, @repository.changesets.count
+
+ get "/projects/subproject1/repository/#{@repository.id}/revisions/deff712f05a90d96edbd70facc47d944be5897e3/entry/new_file.txt"
+ assert_response :success
+
+ assert l1 = css_select("#L1").first
+ assert l1_code = css_select(l1, "td.line-code").first
+ assert_match 'This is a brand new file', l1_code.text
+ end
+ else
+ puts "Git test repository NOT FOUND. Skipping integration tests !!!"
+ def test_fake; assert true end
end
end
diff --git a/test/integration/routing/repositories_test.rb b/test/integration/routing/repositories_test.rb
index 15f707091..2d5a66ff1 100644
--- a/test/integration/routing/repositories_test.rb
+++ b/test/integration/routing/repositories_test.rb
@@ -20,7 +20,9 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingRepositoriesTest < Redmine::RoutingTest
def setup
- @paths = ['path/to/file.c', 'path/to/index.html', 'raw/file.c']
+ @paths = ['path/to/index.html',
+ 'path/to/file.c', 'path/to/file.yaml', 'path/to/file.txt',
+ 'raw/file.c']
end
def test_repositories_resources
@@ -52,25 +54,33 @@ class RoutingRepositoriesTest < Redmine::RoutingTest
should_route 'GET /projects/foo/repository/foo/revisions/2457' => 'repositories#revision', :id => 'foo', :repository_id => 'foo', :rev => '2457'
should_route 'GET /projects/foo/repository/foo/revisions/2457/show' => 'repositories#show', :id => 'foo', :repository_id => 'foo', :rev => '2457', :format => 'html'
- should_route 'GET /projects/foo/repository/foo/revisions/2457/diff' => 'repositories#diff', :id => 'foo', :repository_id => 'foo', :rev => '2457', :format => 'html'
+ should_route 'GET /projects/foo/repository/foo/revisions/2457/diff' => 'repositories#diff', :id => 'foo', :repository_id => 'foo', :rev => '2457'
- %w(show diff entry raw annotate).each do |action|
+ %w(show entry raw annotate).each do |action|
@paths.each do |path|
should_route "GET /projects/foo/repository/foo/revisions/2457/#{action}/#{path}" => "repositories##{action}",
:id => 'foo', :repository_id => 'foo', :rev => '2457', :path => path, :format => 'html'
end
end
+ @paths.each do |path|
+ should_route "GET /projects/foo/repository/foo/revisions/2457/diff/#{path}" => "repositories#diff",
+ :id => 'foo', :repository_id => 'foo', :rev => '2457', :path => path
+ end
end
def test_repositories_non_revisions_path_with_repository_id
should_route 'GET /projects/foo/repository/svn/changes' => 'repositories#changes', :id => 'foo', :repository_id => 'svn', :format => 'html'
- %w(changes diff browse entry raw annotate).each do |action|
+ %w(changes browse entry raw annotate).each do |action|
@paths.each do |path|
should_route "GET /projects/foo/repository/svn/#{action}/#{path}" => "repositories##{action}",
:id => 'foo', :repository_id => 'svn', :path => path, :format => 'html'
end
end
+ @paths.each do |path|
+ should_route "GET /projects/foo/repository/svn/diff/#{path}" => "repositories#diff",
+ :id => 'foo', :repository_id => 'svn', :path => path
+ end
end
def test_repositories_related_issues_with_repository_id