Created
August 4, 2013 06:52
-
-
Save 44uk/6149476 to your computer and use it in GitHub Desktop.
Export diff files between 2 revisions.
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
#!/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