Rake task to help manage svn rename
I recently had to rename several views+controllers in a project. This is a very wearisome task since its not just a directory or a file; but directories, files, tests, fixtures, and other files that get generated by the Rails generator helpers. I searched for a little piece of code to help manage this, but didn't find anything. That may be due to the fact that earlier versions of rake did not work with arguments very well.
Here is my little rake task, you can put it into a file in your lib/tasks directory and run it using:
$rake svn:rename[old_name,new_name] # notice no spaces
And here is the code:
namespace :svn do
FILES_TO_RENAME = [ "app/views/%s",
"app/controllers/%s_controller.rb",
"app/models/%s.rb",
"test/unit/%s_test.rb",
"test/functional/%s_controller_test.rb",
"test/fixtures/%s.yml"]
task :rename, :from, :to do |t, args|
FILES_TO_RENAME.each do |s|
from_f = s % args.from
to_f = s % args.to
if File.exists?(File.expand_path(from_f))
puts "Renaming #{from_f} -> #{to_f}"
puts %x[svn mv #{from_f} #{to_f}]
else
puts "Skipping #{from_f}. File not found."
end
end
end
end
Please leave comments if you see a way to improve this. Feel free to modify it to your needs and tell me about it.
