Skip to content

Commit

Permalink
Support leading and trailing spaces in filenames or directories in th…
Browse files Browse the repository at this point in the history
…e git adapter. #6499

Contributed by Felix Schäfer
  • Loading branch information
thegcat committed Sep 26, 2010
1 parent bd51119 commit 1200f73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/redmine/scm/adapters/git_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def entries(path=nil, identifier=nil)
shellout(cmd) do |io|
io.each_line do |line|
e = line.chomp.to_s
if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\s+(.+)$/
if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\t(.+)$/
type = $1
sha = $2
size = $3
Expand Down Expand Up @@ -165,13 +165,13 @@ def revisions(path, identifier_from, identifier_to, options={})
parsing_descr = 1
changeset[:description] = ""
elsif (parsing_descr == 1 || parsing_descr == 2) \
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/
parsing_descr = 2
fileaction = $1
filepath = $2
files << {:action => fileaction, :path => filepath}
elsif (parsing_descr == 1 || parsing_descr == 2) \
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\s+(.+)$/
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/
parsing_descr = 2
fileaction = $1
filepath = $3
Expand Down
Binary file modified test/fixtures/repositories/git_repository.tar.gz
Binary file not shown.
10 changes: 9 additions & 1 deletion test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_branches
end

def test_getting_all_revisions
assert_equal 14, @adapter.revisions('',nil,nil,:all => true).length
assert_equal 15, @adapter.revisions('',nil,nil,:all => true).length
end

def test_getting_certain_revisions
Expand All @@ -24,6 +24,14 @@ 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_getting_revisions_with_leading_and_trailing_spaces_in_filename
assert_equal " filename with a leading space.txt ", @adapter.revisions(" filename with a leading space.txt ", nil, nil, :all => true)[0].paths[0][:path]
end

def test_getting_entries_with_leading_and_trailing_spaces_in_filename
assert_equal " filename with a leading space.txt ", @adapter.entries('', '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
end

def test_annotate
annotate = @adapter.annotate('sources/watchers_controller.rb')
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
Expand Down
8 changes: 4 additions & 4 deletions test/unit/repository_git_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_fetch_changesets_from_scratch
@repository.fetch_changesets
@repository.reload

assert_equal 14, @repository.changesets.count
assert_equal 23, @repository.changes.count
assert_equal 15, @repository.changesets.count
assert_equal 24, @repository.changes.count

commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
Expand All @@ -57,10 +57,10 @@ def test_fetch_changesets_incremental
# Remove the 3 latest changesets
@repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
@repository.reload
assert_equal 11, @repository.changesets.count
assert_equal 12, @repository.changesets.count

@repository.fetch_changesets
assert_equal 14, @repository.changesets.count
assert_equal 15, @repository.changesets.count
end
else
puts "Git test repository NOT FOUND. Skipping unit tests !!!"
Expand Down

0 comments on commit 1200f73

Please sign in to comment.