This is a subversion pre-commit hook that prevents a Ruby on Rails migration being committed that has the same version as an existing migration. To install you place this in a file called pre-commit in the hooks directory of your subversion repository. You can read about hooks here: http://svnbook.red-bean.com/en/1.0/ch05s02.html
repo_path = ARGV[0]
transaction = ARGV[1]
svnlook = '/usr/bin/svnlook'
commit_dirs_changed = `
commit_changed = `
commit_log = `
files = commit_changed.split(/\n/)
current_migrations = nil
for file in files
if(file =~ /A\s*(.*?\/migrate\/)(\d+)(.*)/)
migration_path = $1
migration_version = $2
if(current_migrations == nil)
current_migrations = {}
migration_files = `
for migration in migration_files
current_migrations[$1] = true if(migration =~ /\s*(\d+)_(.*)/)
end
end
if(current_migrations[migration_version])
STDERR.puts("The is a pre-existing migration with version #{migration_version} in #{migration_path}")
exit(1)
end
end
end