-
-
Save copitux/2894445 to your computer and use it in GitHub Desktop.
Simple script converting git patch file into tortoise merge compatible format. Usage: gitp2svnp.rb <git_patch_file>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') 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) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment