If you’re running Rails 1.0RC or 0.14.1+, drop the following code in a file entitled `svn.rake` in the `lib/tasks` directory of your rails application:
desc "Configure Subversion for Rails" task :configure_for_svn do system "svn remove log/*" system "svn commit -m 'removing all log files from subversion'" system 'svn propset svn:ignore "*.log" log/' system "svn update log/" system "svn commit -m 'Ignoring all files in /log/ ending in .log'" system 'svn propset svn:ignore "*.db" db/' system "svn update db/" system "svn commit -m 'Ignoring all files in /db/ ending in .db'" system "svn move config/database.yml config/database.example" system "svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'" system 'svn propset svn:ignore "database.yml" config/' system "svn update config/" system "svn commit -m 'Ignoring database.yml'" end desc "Add new files to subversion" task :add_new_files do system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add" end desc "shortcut for adding new files" task :add => [ :add_new_files ]
###What’s that gonna do?
It eases the process of importing a new Rails project into subversion by ignoring and/or removing files that you probably don’t want under version control: database config files (for security reasons), databases, and log files.
It _will delete your database.yml_, so I don’t recommend running the task on anything but a brand new project.
Follow my lead:
% rails project
…
Now would be a good time to drop `svn.rake` in the proper spot…
% svn import project_http://your.svn.server.here/project
…
% svn checkout http://your.svn.server.here/project project-svn
…
% cd project-svn
% rake configure_for_svn
In those five steps, you’ve created a fresh Rails project, imported it into a subversion repository, checked it back out into a working copy (you really don’t need the original directory after that), and then moved into your working copy and configured it properly for Subversion, according to [this page on the Rails wiki][1].
[1]: http://wiki.rubyonrails.com/rails/pages/HowtoUseRailsWithSubversion
The other two commands make it easier to put new files under version control, useful after using `script/generate` commands.
Just type `rake add` and watch it go!
_Oh, and please… if you’ve never used SVN before, don’t consider this a tutorial. It’s not. [Go read this one][2] to get started, then come back here._
[2]: http://www.germane-software.com/~ser/R_n_R/subversion.html
14 Comments
Good stuff.
We need to distribute more tasks like this now that we have a tidy lib/tasks folder to use.
Don’t forget that you can throw the -c flag onto your script/generate commands to automatically run “svn add” on generated files.
Whoa.
I did not know that.
Where did you find that??
I also recommend adding:
svn propset svn:ignore -R “.DS_Store” .
to the configure_for_svn rake script if you are in Mac OS X. OS X puts in .DS_Store files in unix directories to remember icon positions and you don’t want to check those in.
Good stuff. This really ought to be in rails proper.
Great post! I have extended this a bit, creating a script which you run instead of the rails command–i.e.
./svnrails.rb myprojectinstead ofrails myproject.The blog post about it is here and the script itself is here.
Thanks for the idea!
Hello,
Very usefull, THANKS!
I used the svn st | grep … and I needed to modify it so that file names with spaces and unusual characters would work on my OS X (using Terminal.app). Here’s the modified command if it helps anyone:
BTW, what it does is surround the string provided to xargs at the end of the pipe with quotations, so you get svn add “arg”
thanks for the GREAT post! Very useful…
The contests on online are interesting and easy to participate
Please suggest sites which conduct online contests .
The contests on online are interesting and easy to participate
Please suggest sites which conduct online contests .
Some of the interesting ways to spend time online is to participate in
contests conducted online . Click here for more information on contests
sporotrichum octastylos isatide fishmonger breth herzegovinian unprepare journalizer
Humane Society of Canada
http://www.news.cornell.edu/releases/Nov00/energy.davis.deb.html
sporotrichum octastylos isatide fishmonger breth herzegovinian unprepare journalizer
Orbiscope
http://www.ocsys.com
liquidate downloader program killr worm liquidate windows antispyware removing malware malware kill removing adware removing trojan horse worm scanner of charge antyspyware
One Trackback/Pingback
[…] found several pages on the internets that discuss how to do a good subversion setup, and they each had their strong […]
Post a Comment