Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Simple script converting git patch file into tortoise merge compatible format. Usage: gitp2svnp.rb <git_patch_file>

View gitp2svnp.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/usr/bin/ruby
 
if ARGV.length != 1
puts "usage: git2svn <file_name>"
puts " file_name - git patch file name"
exit
end
 
separator = "\n===================================================================\n"
new_file = false
content = ''
git_patch = ARGV[0]
 
File.open(git_patch, 'r:utf-8') do |file|
lines = file.readlines
lines.each do |line|
line.gsub!(/^--- a\/(.*)/, 'Index: \1' + separator + '--- \1')
if line =~ /^--- \/.*/
new_file = true
line.gsub!(/.*/,'')
end
if line =~ /^\+\+\+ b\/(.*)/
line.gsub!(/^\+\+\+ b\/(.*)/, '+++ \1')
if new_file == true
new_file = false
line.gsub!(/^\+\+\+ (.*)/,'Index: \1' + separator + '--- \1' + "\n" + '+++ \1')
end
end
content += line
end
end
 
svn_patch = git_patch.dup
if svn_patch =~ /\.patch$/
index = svn_patch.rindex('.patch')
svn_patch = svn_patch.insert(index, '.svn')
else
svn_patch += '.svn.patch'
end
 
File.open(svn_patch, 'w') { |f| f.write(content) }

This doesn't work right for new files with svn 1.7. The new empty file gets created and added to svn, but then the patch to add its contents is rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.