Created
November 18, 2008 17:38
-
-
Save singpolyma/26185 to your computer and use it in GitHub Desktop.
This file contains 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
# Generates a patch by comparing two directories using a simple logfile format | |
# A relative/path for added files (will be directly copied) | |
# D relative/path for removed files (will be directly removed using the command defined in RM) | |
# M relative/path for modified files (will be included in the output patch) | |
olddir = ARGV[0] # Unchanged | |
newdir = ARGV[1] # Changes | |
unless olddir && newdir | |
warn 'ERROR, must pass two directories' | |
exit 1 | |
end | |
RM = 'svn rm' # Change to rm -fv for non-svn use | |
$stdin.read.split(/\n/).each do |item| | |
item = item.split(/ /) | |
case item[0] | |
when 'M' | |
# Just output the diff of modified files, for patching | |
puts `diff -u "#{olddir}/#{item[1]}" "#{newdir}/#{item[1]}"` | |
when 'A' | |
# Copy over new files | |
$stderr.puts `cp -v "#{newdir}/#{item[1]}" "#{olddir}/#{item[1]}"` | |
when 'D' | |
# Delete removed files | |
$stderr.puts `#{RM} "#{olddir}/#{item[1]}"` | |
else | |
warn 'WARN: unknown merge type ' + item[0] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment