Skip to content

Instantly share code, notes, and snippets.

@44uk
Created August 4, 2013 06:52
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 44uk/6149476 to your computer and use it in GitHub Desktop.
Save 44uk/6149476 to your computer and use it in GitHub Desktop.
Export diff files between 2 revisions.
#!/usr/bin/env ruby
#
#= Export diff files between 2 revisions.
#
# export only commited files for SourceTree.
#
#== setup
#
# set this script to cunstom action.
# then, set "$REPO $SHA" in parameters.
#
#== usage
#
# select one or more revisions and execute custom action.
# then, create archive to parent directory of PROJECT_ROOT.
# this archive contains files commited in selected revisions.
#
root = ARGV.shift
dir = File.basename(root)
from = ARGV.first
to = ARGV.last
format = "zip"
output = "#{root}/../#{dir}.#{format}"
# if not selected multiple revision
# TODO: tell me more better way.
if from === to
to = %x[git log --pretty=oneline | cut -d' ' -f1 | grep -A1 #{from} | tail -1]
to = to.strip
end
puts "root :" + "#{root}"
puts "dir :" + "#{dir}"
puts "from :" + "#{from}"
puts "to :" + "#{to}"
puts "format:" + "#{format}"
puts "output:" + "#{output}"
diff = "git diff --name-only #{to} #{from}"
cmd = "git archive --format=#{format} --prefix=#{dir}2/ #{from} `#{diff}` -o #{output}"
puts "cmd :" + cmd
%x[#{cmd}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment