Support spaces in the files or directories in the git adapter. #6054

Contributed by Felix Schäfer

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4188 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-09-26 19:07:46 +00:00
parent 319849caf8
commit bd51119460
5 changed files with 25 additions and 12 deletions

View File

@ -88,7 +88,7 @@ module Redmine
return nil if path.nil? return nil if path.nil?
cmd = "#{GIT_BIN} --git-dir #{target('')} log --date=iso --pretty=fuller --no-merges -n 1 " cmd = "#{GIT_BIN} --git-dir #{target('')} log --date=iso --pretty=fuller --no-merges -n 1 "
cmd << " #{shell_quote rev} " if rev cmd << " #{shell_quote rev} " if rev
cmd << "-- #{path} " unless path.empty? cmd << "-- #{shell_quote path} " unless path.empty?
shellout(cmd) do |io| shellout(cmd) do |io|
begin begin
id = io.gets.split[1] id = io.gets.split[1]
@ -121,7 +121,7 @@ module Redmine
cmd << "#{shell_quote(identifier_from + '..')}" if identifier_from cmd << "#{shell_quote(identifier_from + '..')}" if identifier_from
cmd << "#{shell_quote identifier_to}" if identifier_to cmd << "#{shell_quote identifier_to}" if identifier_to
cmd << " --since=#{shell_quote(options[:since].strftime("%Y-%m-%d %H:%M:%S"))}" if options[:since] cmd << " --since=#{shell_quote(options[:since].strftime("%Y-%m-%d %H:%M:%S"))}" if options[:since]
cmd << " -- #{path}" if path && !path.empty? cmd << " -- #{shell_quote path}" if path && !path.empty?
shellout(cmd) do |io| shellout(cmd) do |io|
files=[] files=[]

Binary file not shown.

View File

@ -50,7 +50,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase
assert_response :success assert_response :success
assert_template 'show' assert_template 'show'
assert_not_nil assigns(:entries) assert_not_nil assigns(:entries)
assert_equal 7, assigns(:entries).size assert_equal 8, assigns(:entries).size
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
@ -58,6 +58,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase
assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
end end
def test_browse_branch def test_browse_branch

View File

@ -13,13 +13,17 @@ class GitAdapterTest < ActiveSupport::TestCase
end end
def test_getting_all_revisions def test_getting_all_revisions
assert_equal 13, @adapter.revisions('',nil,nil,:all => true).length assert_equal 14, @adapter.revisions('',nil,nil,:all => true).length
end end
def test_getting_certain_revisions def test_getting_certain_revisions
assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length assert_equal 1, @adapter.revisions('','899a15d^','899a15d').length
end end
def test_getting_revisions_with_spaces_in_filename
assert_equal 1, @adapter.revisions("filemane with spaces.txt", nil, nil, :all => true).length
end
def test_annotate def test_annotate
annotate = @adapter.annotate('sources/watchers_controller.rb') annotate = @adapter.annotate('sources/watchers_controller.rb')
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
@ -29,6 +33,12 @@ class GitAdapterTest < ActiveSupport::TestCase
assert_equal "jsmith", annotate.revisions[4].author assert_equal "jsmith", annotate.revisions[4].author
end end
def test_annotate_moved_file
annotate = @adapter.annotate('renamed_test.txt')
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
assert_equal 2, annotate.lines.size
end
def test_last_rev def test_last_rev
last_rev = @adapter.lastrev("README", "4f26664364207fa8b1af9f8722647ab2d4ac5d43") last_rev = @adapter.lastrev("README", "4f26664364207fa8b1af9f8722647ab2d4ac5d43")
assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
@ -37,10 +47,12 @@ class GitAdapterTest < ActiveSupport::TestCase
assert_equal "2009-06-24 05:27:38".to_time, last_rev.time assert_equal "2009-06-24 05:27:38".to_time, last_rev.time
end end
def test_annotate_moved_file def test_last_rev_with_spaces_in_filename
annotate = @adapter.annotate('renamed_test.txt') last_rev = @adapter.lastrev("filemane with spaces.txt", "ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
assert_equal 2, annotate.lines.size assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
assert_equal "Felix Schäfer <felix@fachschaften.org>", last_rev.author
assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
end end
else else
puts "Git test repository NOT FOUND. Skipping unit tests !!!" puts "Git test repository NOT FOUND. Skipping unit tests !!!"

View File

@ -34,8 +34,8 @@ class RepositoryGitTest < ActiveSupport::TestCase
@repository.fetch_changesets @repository.fetch_changesets
@repository.reload @repository.reload
assert_equal 13, @repository.changesets.count assert_equal 14, @repository.changesets.count
assert_equal 22, @repository.changes.count assert_equal 23, @repository.changes.count
commit = @repository.changesets.find(:first, :order => 'committed_on ASC') commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
@ -57,10 +57,10 @@ class RepositoryGitTest < ActiveSupport::TestCase
# Remove the 3 latest changesets # Remove the 3 latest changesets
@repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy) @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
@repository.reload @repository.reload
assert_equal 10, @repository.changesets.count assert_equal 11, @repository.changesets.count
@repository.fetch_changesets @repository.fetch_changesets
assert_equal 13, @repository.changesets.count assert_equal 14, @repository.changesets.count
end end
else else
puts "Git test repository NOT FOUND. Skipping unit tests !!!" puts "Git test repository NOT FOUND. Skipping unit tests !!!"