Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created November 18, 2008 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singpolyma/26185 to your computer and use it in GitHub Desktop.
Save singpolyma/26185 to your computer and use it in GitHub Desktop.
# 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