Skip to content

Instantly share code, notes, and snippets.

@L2G
Last active August 29, 2015 14:20
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 L2G/9eb71a3bfef953dff15e to your computer and use it in GitHub Desktop.
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
#!/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