Skip to content

Instantly share code, notes, and snippets.

@bitbutter
Created February 28, 2009 11:52
Show Gist options
  • Save bitbutter/71939 to your computer and use it in GitHub Desktop.
Save bitbutter/71939 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# This script lives in [working directory]/git_helpers/
# It gets called from a git pre-commit hook.
# It automatically adds timestamp information to max/msp object ids
# if they don't already have a timestamp.
# A start towards intelligent .maxpat merges in git-managed max/msp projects.
require 'find'
require 'fileutils'
# Use the same string to enrich all new (Untimestamped) id strings in this commit
timestamp_string=Time.now.strftime("%Y%m%d%H%M%S"+Time.now.usec.to_s)
def enrich_object_ids(path,timestamp_string)
content = File.read(path)
insertions_made=false
if content.gsub!(/obj-(.)"/, 'obj-\1-'+timestamp_string+'"')
insertions_made=true
end
if insertions_made
File.open(path, 'wb') { |file| file.write(content) }
p path+(" I enriched object ids with a timestamp!")
end
end
Find.find('./') do |path|
if File.basename(path).include?('.maxpat')
enrich_object_ids(path,timestamp_string)
end
end
#!/bin/sh
# This lives in [working directory]/.git/hooks/
# To enable this hook, run the following from your working directory:
# chmod 744 .git/hooks/pre-commit
ruby $PWD/git_helpers/add_object_timestamps.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment