fe399d54edc9e871d42b4c3f80ccef4756b0dff0

Author: Robin Luckey

Date: 2009-02-13 11:30:11 -0800

[FIX] Fixes ticket 9. Allow renames to the empty string.

diff --git a/lib/scm/parsers/bzr_parser.rb b/lib/scm/parsers/bzr_parser.rb index bedfb36..a693be0 100644 --- a/lib/scm/parsers/bzr_parser.rb +++ b/lib/scm/parsers/bzr_parser.rb @@ -89,10 +89,13 @@ module Scm::Parsers case action when :rename # A rename action requires two diffs: one to remove the old filename, - # another to add the new filename - before, after = line.scan(/(.+) => (.+)/).first + # another to add the new filename. + # + # Note that is possible to be renamed to the empty string! + # This happens when a subdirectory is moved to become the root. + before, after = line.scan(/(.+) => ?(.*)/).first [ Scm::Diff.new(:action => 'D', :path => before), - Scm::Diff.new(:action => 'A', :path => after )] + Scm::Diff.new(:action => 'A', :path => after || '' )] else [Scm::Diff.new(:action => action, :path => line)] end.each do |d| diff --git a/test/unit/bzr_parser_test.rb b/test/unit/bzr_parser_test.rb index 59e9060..ebe6696 100644 --- a/test/unit/bzr_parser_test.rb +++ b/test/unit/bzr_parser_test.rb @@ -405,5 +405,33 @@ added: assert_equal 1, commits.last.diffs.size assert_equal "helloworld.c", commits.last.diffs.first.path end + + # In this example, directory "test/" is renamed to "/". + # This shows in the log as being renamed to an empty string. + def test_directory_renamed_to_root + log = <<-SAMPLE + ------------------------------------------------------------ + revno: 220.90.1 + revision-id: info@ohloh.net-20081002201109-j4z0r2c8nsgbm2vk + parent: info@ohloh.net-20081002200737-pjao1idjcrxpk4n4 + committer: Ohloh <info@ohloh.net> + branch nick: subvertpy + timestamp: Thu 2008-10-02 22:11:09 +0200 + message: + Promote the test directory to the root. + renamed: + test => test-20081002184530-hz9mrr3wqq4l8qdx-1 + SAMPLE + + commits = BzrParser.parse(log) + + assert_equal 1, commits.size + assert_equal 'info@ohloh.net-20081002201109-j4z0r2c8nsgbm2vk', commits.first.token + assert_equal 2, commits.first.diffs.size + assert_equal "D", commits.first.diffs.first.action + assert_equal "test", commits.first.diffs.first.path + assert_equal "A", commits.first.diffs.last.action + assert_equal "", commits.first.diffs.last.path + end end end