lib/svn2git/migration.rb in svn2git-2.2.0 vs lib/svn2git/migration.rb in svn2git-2.2.1

- old
+ new

@@ -99,11 +99,11 @@ opts.on('--no-minimize-url', 'Accept URLs as-is without attempting to connect to a higher level directory') do options[:nominimizeurl] = true end - opts.on('--revision REV', 'Start importing from SVN revision') do |revision| + opts.on('--revision START_REV[:END_REV]', 'Start importing from SVN revision START_REV; optionally end at END_REV') do |revision| options[:revision] = revision end opts.on('-m', '--metadata', 'Include metadata in git logs (git-svn-id)') do options[:metadata] = true @@ -179,11 +179,15 @@ end run_command("git config --local svn.authorsfile #{authors}") unless authors.nil? cmd = "git svn fetch " - cmd += "-r #{revision}:HEAD " unless revision.nil? + unless revision.nil? + range = revision.split(":") + range[1] = "HEAD" unless range[1] + cmd += "-r #{range[0]}:#{range[1]} " + end unless exclude.empty? # Add exclude paths to the command line; some versions of git support # this for fetch only, later also for init. regex = [] unless rootistrunk @@ -209,12 +213,12 @@ @tags = @remote.find_all { |b| b.strip =~ %r{^svn\/tags\/} } end def fix_tags current = {} - current['user.name'] = run_command("git config --local --get user.name") - current['user.email'] = run_command("git config --local --get user.email") + current['user.name'] = run_command("git config --local --get user.name", false) + current['user.email'] = run_command("git config --local --get user.email", false) @tags.each do |tag| tag = tag.strip id = tag.gsub(%r{^svn\/tags\/}, '').strip subject = run_command("git log -1 --pretty=format:'%s' '#{escape_quotes(tag)}'") @@ -226,17 +230,20 @@ run_command("GIT_COMMITTER_DATE='#{escape_quotes(date)}' git tag -a -m '#{escape_quotes(subject)}' '#{escape_quotes(id)}' '#{escape_quotes(tag)}'") run_command("git branch -d -r '#{escape_quotes(tag)}'") end ensure - current.each_pair do |name, value| - # If a line was read, then there was a config value so restore it. - # Otherwise unset the value because originally there was none. - if value[-1] == "\n" - run_command("git config --local #{name} '#{value.chomp("\n")}'") - else - run_command("git config --local --unset #{name}") + # We only change the git config values if there are @tags available. So it stands to reason we should revert them only in that case. + unless @tags.empty? + current.each_pair do |name, value| + # If a line was read, then there was a config value so restore it. + # Otherwise unset the value because originally there was none. + if value.strip != '' + run_command("git config --local #{name} '#{value.strip}'") + else + run_command("git config --local --unset #{name}") + end end end end def fix_branches @@ -276,11 +283,11 @@ def optimize_repos run_command("git gc") end - def run_command(cmd) + def run_command(cmd, exit_on_error=true) log "Running command: #{cmd}" ret = '' cmd = "2>&1 #{cmd}" @@ -289,10 +296,10 @@ log line ret << line end end - unless $?.exitstatus == 0 + if exit_on_error && ($?.exitstatus != 0) $stderr.puts "command failed:\n#{cmd}" exit -1 end ret