Last active
August 29, 2015 14:20
-
-
Save L2G/9eb71a3bfef953dff15e to your computer and use it in GitHub Desktop.
Proof of concept: filter a Git tree so that all files have timestamps matching the last commit to touch them
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 | |
OUTPUT = ARGV[0] | |
# Convert Git timestamp into Ruby time | |
timestamp = Time.at(ENV['GIT_AUTHOR_DATE'].delete('@').to_i) | |
# Collect all real files added or modified in the commit | |
files = [] | |
%x(git show --raw #{ENV['GIT_COMMIT']}).split("\n").each do |line| | |
next unless /^:/.match(line) | |
#$stderr.puts | |
#$stderr.puts line.inspect | |
(fields, file) = line.split("\t") | |
fields = fields.split(/\s/) | |
#$stderr.puts fields.inspect | |
files << file if /^100/.match(fields[1]) | |
end | |
unless files.empty? | |
File.open(OUTPUT, "a") do |file| | |
file.puts ["touch -c -t", timestamp.strftime("%Y%m%d%H%M.%S"), *files].join(" ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment