lib/svn2git/migration.rb in svn2git-1.3.1 vs lib/svn2git/migration.rb in svn2git-1.3.2
- old
+ new
@@ -127,11 +127,11 @@
cmd += @url
run_command(cmd)
end
- run_command("git config svn.authorsfile #{authors}") if authors
+ run_command("git config svn.authorsfile #{authors}") unless authors.nil?
cmd = "git svn fetch"
unless exclude.empty?
# Add exclude paths to the command line; some versions of git support
# this for fetch only, later also for init.
@@ -148,31 +148,37 @@
get_branches
end
def get_branches
- @remote = `git branch -r`.split(/\n/)
+ @local = run_command("git branch -l").split(/\n/).collect{ |b| b.strip }
+ @remote = run_command("git branch -r").split(/\n/).collect{ |b| b.strip }
@tags = @remote.find_all { |b| b.strip =~ %r{^tags\/} }
end
def fix_tags
@tags.each do |tag|
- id = tag.strip.gsub(%r{^tags\/}, '')
- subject = `git log -1 --pretty=format:"%s" #{tag.strip()}`
- date = `git log -1 --pretty=format:"%ci" #{tag.strip()}`
- run_command("GIT_COMMITTER_DATE='#{date}' git tag -a -m '#{subject}' '#{id.strip()}' '#{tag.strip()}'")
- run_command("git branch -d -r #{tag.strip()}")
+ tag = tag.strip
+ id = tag.gsub(%r{^tags\/}, '').strip
+ subject = run_command("git log -1 --pretty=format:'%s' #{tag}")
+ date = run_command("git log -1 --pretty=format:'%ci' #{tag}")
+ subject = escape_quotes(subject)
+ date = escape_quotes(date)
+ id = escape_quotes(id)
+ run_command("GIT_COMMITTER_DATE='#{date}' git tag -a -m '#{subject}' '#{id}' '#{escape_quotes(tag)}'")
+ run_command("git branch -d -r #{tag}")
end
end
def fix_branches
svn_branches = @remote.find_all { |b| not @tags.include?(b) }
svn_branches.each do |branch|
branch = branch.strip
next if branch == 'trunk'
+
run_command("git checkout #{branch}")
- run_command("git checkout -b #{branch}")
+ run_command("git checkout -b #{branch}")
end
end
def fix_trunk
trunk = @remote.find { |b| b.strip == 'trunk' }
@@ -189,24 +195,33 @@
end
def run_command(cmd)
log "Running command: #{cmd}"
+ ret = ''
+
IO.popen(cmd) do |stdout|
stdout.each do |line|
log line
+ ret << line
end
end
+
+ ret
end
def log(msg)
puts msg if @options[:verbose]
end
def show_help_message(msg)
puts "Error starting script: #{msg}\n\n"
puts @opts.help
exit
+ end
+
+ def escape_quotes(str)
+ str.gsub("'", "'\\\\''")
end
end
end