This assumes that you have already created a subversion repository, and you are just wondering how to setup your rails project.
If you have WEBrick or lighttpd running after running “script/server” in your rails directory, shutdown the server.
svn import . repository_url -m "Import" --username usermv your_rails_app your_rails_app-backupsvn checkout svn_url_to_your_repository your_rails_appsvn remove log/*svn commit -m "removing all log files from subversion"svn propset svn:ignore "*.log" log/svn update log/svn commit -m "Ignoring all files in /log/ ending in .log"svn propset svn:ignore "*" tmp/sessions tmp/cache tmp/socketssvn commit -m "Ignoring all files in /tmp/"svn move config/database.yml config/database.examplesvn commit -m "Moving database.yml to database.example to provide a template for anyone who checks out the code"svn propset svn:ignore "database.yml" config/svn update config/svn commit -m "Ignoring database.yml"
svn remove tmp/*
svn propset svn:ignore "*" tmp/
svn update tmp/
svn commit -m "ignore tmp/ content from now"
You’re done. Now your log files will not be checked into subversion on a commit, and you don’t need to worry about the database settings on your development machine and your production machine and things breaking as database.yml moves between them.
Feel free to skip the steps where you remove database.yml, but if you are working with several other programmers who may have different database.yml files you may want to keep it ignored.
—
Another solution to accomodate multiple developer’s database setup would be to grab those parameters from the “environment”, each programmer’s own development environment that is. You could write database.yml like so:
development:
adapter: mysql
database: <%= ENV['DEV_DB'] %>
host: <%= ENV['DEV_HOST'] %>
username: <%= ENV['DEV_USER'] %>
password: "<%= ENV['DEV_PASS'] %>"
Even production params could be specified like this too, which would help keep sensitive info out of the code repository.
WARNING
Settings environment variables on a shared host could be insecure. If you can run everything setuid and make your .[shell]rc and .htaccess files mode 0700 this would be a little more acceptable on a shared host.
—
Adding all new files to Subversion after running a generate script:
If you’re running Rails 0.14.3 or newer, the generator scripts can take the —svn (or -c) option to automatically add the created files via Subversion.
./script/generate scaffold controller_name --svn
Run
./script/generatewithout command line options for details.
—
Subversion has an option for “svn add” to make things much easier, by using “svn add * --force”.
svn --force add .
—
I found that svn add * --force is not a perfect solution, as it will force to add ignored resources into repository. In my machine, It automatically adds my ignored *.log files into respository. Those log files are ignored by using “svn propset svn:ignore *.log log/”.
Is this a bug of SVN?
—
The --force option does seem to override ignored resources, which can really throw a monkey wrench in your system. The following shell commands provide a nice way around that. They take the output from svn status and use it as input for svn add:
svn status | grep "^\?" | awk "{print $2}" | xargs svn add
Also, if you have filenames that include spaces, you can try:
svn status | grep "^\?" | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add
You can put these in a shell script or just run them from the command line on -nix. There was also a similar windows script on this page at one point, but it seems to have vanished.
—
This will work from the commandline – $ drives interpolation in bash.
svn status | awk '/^\?/ {print $2}'|xargs svn add
I added this alias to my TILDEHERE/.bash_profile
alias svnaddall='svn status | grep "^\?" | awk "{print \$2}" | xargs svn add'
I’ve created a script named railscommit in my app’s script directory which I use to do commits to our svn repository. Here’s the contents, I’m not an experienced bash script writer so any improvements are welcome:
#!/bin/bash
echo ""
echo "Here's what we're going to do:"
echo " "
echo "Add the following files"
echo "-----------------------"
svn status | awk '/^\?/ {print $2}'
echo " "
echo "Remove the following files"
echo "--------------------------"
svn status | awk '/^!/ {print $2}'
echo " "
echo "Check in the following modified files"
echo "-------------------------------------"
svn status | awk '/^M/ {print $2}'
echo " "
echo "Proceed with commit? [yn]"
read answer
if [ "$answer" = "y" ]
then
echo " "
echo "Adding the following files"
svn status | awk '/^\?/ {print $2}' | xargs svn add
echo " "
echo "Removing the following files"
svn status | awk '/^!/ {print $2}' | xargs svn remove
echo " "
echo "Committing changes to repository"
svn commit
else
echo " "
echo "Commit cancelled"
fi
echo " "
echo "Want to check for updates? [yn]"
read answer
if [ "$answer" = "y" ]
then
svn update
else
echo " "
echo "Update cancelled"
fi
———
Okay my take on this script (in ruby of course):
#!/usr/bin/env ruby
# my take on a easy commit script for rails...
# it is far from prefect, so:
# please feed back the modifications you made to it!
#
# by Cies Breijs -- cies.breijsATgmailDOTcom
# based on a bash script by Anonymous Gentleman
# found here: http:</code><code>//wiki.rubyonrails.org/rails/pages/HowtoUseRailsWithSubversion
to_add = []
to_remove = []
to_checkin = []
`svn status`.each_line do |l|
action_char, path = l.split(' ', 2)
path.strip!
case action_char
when '?'
to_add << path
when '!'
to_remove << path
when 'M'
to_checkin << path
end
end
puts "\nyou are about to..."
def print_list(array, str)
puts "\n#{str}:"
array.each { |i| puts "\t"+i }
puts "\t<nothing>" if array.length == 0
end
print_list(to_add, 'add')
print_list(to_remove, 'remove')
print_list(to_checkin, 'checkin')
puts "\nplease write something for the commit log adn hit enter..."
puts "(hitting enter on an empty line will cancel this commit)\n\n"
log = gets.strip
if log.empty?
puts "commit cancelled!\n"
exit
end
puts "\ncontacting repository...\n"
`svn add #{to_add.join(' ')}`
`svn remove #{to_remove.join(' ')}`
puts "\n" + `svn commit -m "#{log.gsub('"', '\"')}"` + "\n"
puts "running 'svn update' to be shure we are up-to-date..."
puts `svn update`
puts "\nfinished.\n"
Please fead back on it, or modify it…
I’ll update changes I to it here.
- Cies Breijs.
———
Windows Script came back. Drop it into script/ folder with name like:svn_addall.rb, then in RAILS_APP_ROOT, run:ruby script/svn_addall.rb. Good luck!
#######################################
- Author:Yufan Shi
- Email:yufanshi AT gmail.com
- Website:www.feed-tank.com
#######################################
require ‘win32ole’
shell = WIN32OLE.new(‘Wscript.Shell’)
objExec = shell.exec(“svn status”)
while !objExec.stdout.atendofstream
l = objExec.stdout.readline
if l =~ /^\?/
l = l.sub(/^\?( )*/,’svn add ’)
objResult = shell.exec(l)
while !objResult.stdout.atendofstream
print objResult.stdout.readline,“\n”
end
end
end
######################################
—
As my development work shifts between Unix and Windows machines – each environment has Ruby installed in a different location, so each require a different shebang (#!) line at the start of all ‘dispatch.(star)’ files. To deal with this I perform a similar manoeuvre to that described above for database.yml.
couldn’t you just use #!/usr/bin/env ruby to invoke ruby from the path wherever it may be installed? Then you just need to ensure that your path is set correctly on each system, rather than changing your source files for each system. → No such thing as env in Windows, so if you’re switching between Windows and Linux (as mentioned above), this can’t work.
svn move public/dispatch.rb public/dispatch.rb.examplesvn move public/dispatch.cgi public/dispatch.cgi.examplesvn move public/dispatch.fcgi public/dispatch.fcgi.examplesvn commit -m 'Moving dispatch.(star) to dispatch.(star).example to provide a template.'svn propedit svn:ignore public/This will launch subversion’s default text editor, and if you type and save the following info:
dispatch.rb
dispatch.cgi
dispatch.fcgisvn update public/svn commit -m"Ignoring dispatch.* files"That should be that, so that now when I initially check out the project on whatever machine, I just need to create the dispatch.(star) files from the samples, make sure the shebang line is correct, and away I go.
This is spelled out here:
http://subversion.tigris.org/faq.html#website-auto-update
The solution requires three steps:
I’m using this script to initialize a subversioned rails trunk. Maybe it’s useful.
somebody, please review and respond to olegf, if it’s working (not working) for you
Sometimes you want to use plugins for your Rails app. This is how you add them into your project as svn externals.
ruby script/plugin install -x svn_url_to_plugin_repository
svn commit -m "added plugin xxx"
Now this plugin will be checked out into app/vendor/plugins/ and added to your repository as external dependency.
Next time you run
svn update plugin code will be updated from its repository too.
You may want to disable this behaviour and specify the revision for the plugin you want. This is done by
svn propedit svn:externals vendor/plugins
And add revision number after the name of the plugin, like
globalize -r179 svn_url_to_plugin_repository
——
I documented how I create a Rails app and set up SVN revisioning on it over at my website. It’s a fairly straight-forward walkthrough that works well for me so far. YMMV.—GarrettMurray
Creating a New Rails App with SVN
——
I’ve created a ruby script (with the great help of seb and technoweenie) that can be used instead of the rails command to create your application AND import it into the repository “the subversion way”, ignoring various files as per steps 1-10 above (with the exception of #9). For the sake of keeping things DRY, you can find the latest version here: Create a Rails project skeleton and import and checkout from svn all at one
Scroll down to the bottom for the latest version. Use it and change it as much as you like, but post your changes so that I can benefit ;)
My ruby kung-fu is weak, so this code could probably use a good refactoring. Also, as the code is right now, you can’t use the same arguments you do for the regular rails command. Use the rails weenie site (where the code is) to comment and or suggest improvements and or update the code.
——
I spent some time poking around here to figure out how to make my own subversion repository for my rails projects — I’ve compiled what I found from various sources for those who are interested in ssh+svn.
Connecting to your remote SVN repository securely
——
Yet Another Rails + Subversion page.
This assumes that you have already created a subversion repository, and you are just wondering how to setup your rails project.
If you have WEBrick or lighttpd running after running “script/server” in your rails directory, shutdown the server.
svn import . repository_url -m "Import" --username usermv your_rails_app your_rails_app-backupsvn checkout svn_url_to_your_repository your_rails_appsvn remove log/*svn commit -m "removing all log files from subversion"svn propset svn:ignore "*.log" log/svn update log/svn commit -m "Ignoring all files in /log/ ending in .log"svn propset svn:ignore "*" tmp/sessions tmp/cache tmp/socketssvn commit -m "Ignoring all files in /tmp/"svn move config/database.yml config/database.examplesvn commit -m "Moving database.yml to database.example to provide a template for anyone who checks out the code"svn propset svn:ignore "database.yml" config/svn update config/svn commit -m "Ignoring database.yml"
svn remove tmp/*
svn propset svn:ignore "*" tmp/
svn update tmp/
svn commit -m "ignore tmp/ content from now"
You’re done. Now your log files will not be checked into subversion on a commit, and you don’t need to worry about the database settings on your development machine and your production machine and things breaking as database.yml moves between them.
Feel free to skip the steps where you remove database.yml, but if you are working with several other programmers who may have different database.yml files you may want to keep it ignored.
—
Another solution to accomodate multiple developer’s database setup would be to grab those parameters from the “environment”, each programmer’s own development environment that is. You could write database.yml like so:
development:
adapter: mysql
database: <%= ENV['DEV_DB'] %>
host: <%= ENV['DEV_HOST'] %>
username: <%= ENV['DEV_USER'] %>
password: "<%= ENV['DEV_PASS'] %>"
Even production params could be specified like this too, which would help keep sensitive info out of the code repository.
WARNING
Settings environment variables on a shared host could be insecure. If you can run everything setuid and make your .[shell]rc and .htaccess files mode 0700 this would be a little more acceptable on a shared host.
—
Adding all new files to Subversion after running a generate script:
If you’re running Rails 0.14.3 or newer, the generator scripts can take the —svn (or -c) option to automatically add the created files via Subversion.
./script/generate scaffold controller_name --svn
Run
./script/generatewithout command line options for details.
—
Subversion has an option for “svn add” to make things much easier, by using “svn add * --force”.
svn --force add .
—
I found that svn add * --force is not a perfect solution, as it will force to add ignored resources into repository. In my machine, It automatically adds my ignored *.log files into respository. Those log files are ignored by using “svn propset svn:ignore *.log log/”.
Is this a bug of SVN?
—
The --force option does seem to override ignored resources, which can really throw a monkey wrench in your system. The following shell commands provide a nice way around that. They take the output from svn status and use it as input for svn add:
svn status | grep "^\?" | awk "{print $2}" | xargs svn add
Also, if you have filenames that include spaces, you can try:
svn status | grep "^\?" | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add
You can put these in a shell script or just run them from the command line on -nix. There was also a similar windows script on this page at one point, but it seems to have vanished.
—
This will work from the commandline – $ drives interpolation in bash.
svn status | awk '/^\?/ {print $2}'|xargs svn add
I added this alias to my TILDEHERE/.bash_profile
alias svnaddall='svn status | grep "^\?" | awk "{print \$2}" | xargs svn add'
I’ve created a script named railscommit in my app’s script directory which I use to do commits to our svn repository. Here’s the contents, I’m not an experienced bash script writer so any improvements are welcome:
#!/bin/bash
echo ""
echo "Here's what we're going to do:"
echo " "
echo "Add the following files"
echo "-----------------------"
svn status | awk '/^\?/ {print $2}'
echo " "
echo "Remove the following files"
echo "--------------------------"
svn status | awk '/^!/ {print $2}'
echo " "
echo "Check in the following modified files"
echo "-------------------------------------"
svn status | awk '/^M/ {print $2}'
echo " "
echo "Proceed with commit? [yn]"
read answer
if [ "$answer" = "y" ]
then
echo " "
echo "Adding the following files"
svn status | awk '/^\?/ {print $2}' | xargs svn add
echo " "
echo "Removing the following files"
svn status | awk '/^!/ {print $2}' | xargs svn remove
echo " "
echo "Committing changes to repository"
svn commit
else
echo " "
echo "Commit cancelled"
fi
echo " "
echo "Want to check for updates? [yn]"
read answer
if [ "$answer" = "y" ]
then
svn update
else
echo " "
echo "Update cancelled"
fi
———
Okay my take on this script (in ruby of course):
#!/usr/bin/env ruby
# my take on a easy commit script for rails...
# it is far from prefect, so:
# please feed back the modifications you made to it!
#
# by Cies Breijs -- cies.breijsATgmailDOTcom
# based on a bash script by Anonymous Gentleman
# found here: http:</code><code>//wiki.rubyonrails.org/rails/pages/HowtoUseRailsWithSubversion
to_add = []
to_remove = []
to_checkin = []
`svn status`.each_line do |l|
action_char, path = l.split(' ', 2)
path.strip!
case action_char
when '?'
to_add << path
when '!'
to_remove << path
when 'M'
to_checkin << path
end
end
puts "\nyou are about to..."
def print_list(array, str)
puts "\n#{str}:"
array.each { |i| puts "\t"+i }
puts "\t<nothing>" if array.length == 0
end
print_list(to_add, 'add')
print_list(to_remove, 'remove')
print_list(to_checkin, 'checkin')
puts "\nplease write something for the commit log adn hit enter..."
puts "(hitting enter on an empty line will cancel this commit)\n\n"
log = gets.strip
if log.empty?
puts "commit cancelled!\n"
exit
end
puts "\ncontacting repository...\n"
`svn add #{to_add.join(' ')}`
`svn remove #{to_remove.join(' ')}`
puts "\n" + `svn commit -m "#{log.gsub('"', '\"')}"` + "\n"
puts "running 'svn update' to be shure we are up-to-date..."
puts `svn update`
puts "\nfinished.\n"
Please fead back on it, or modify it…
I’ll update changes I to it here.
- Cies Breijs.
———
Windows Script came back. Drop it into script/ folder with name like:svn_addall.rb, then in RAILS_APP_ROOT, run:ruby script/svn_addall.rb. Good luck!
#######################################
- Author:Yufan Shi
- Email:yufanshi AT gmail.com
- Website:www.feed-tank.com
#######################################
require ‘win32ole’
shell = WIN32OLE.new(‘Wscript.Shell’)
objExec = shell.exec(“svn status”)
while !objExec.stdout.atendofstream
l = objExec.stdout.readline
if l =~ /^\?/
l = l.sub(/^\?( )*/,’svn add ’)
objResult = shell.exec(l)
while !objResult.stdout.atendofstream
print objResult.stdout.readline,“\n”
end
end
end
######################################
—
As my development work shifts between Unix and Windows machines – each environment has Ruby installed in a different location, so each require a different shebang (#!) line at the start of all ‘dispatch.(star)’ files. To deal with this I perform a similar manoeuvre to that described above for database.yml.
couldn’t you just use #!/usr/bin/env ruby to invoke ruby from the path wherever it may be installed? Then you just need to ensure that your path is set correctly on each system, rather than changing your source files for each system. → No such thing as env in Windows, so if you’re switching between Windows and Linux (as mentioned above), this can’t work.
svn move public/dispatch.rb public/dispatch.rb.examplesvn move public/dispatch.cgi public/dispatch.cgi.examplesvn move public/dispatch.fcgi public/dispatch.fcgi.examplesvn commit -m 'Moving dispatch.(star) to dispatch.(star).example to provide a template.'svn propedit svn:ignore public/This will launch subversion’s default text editor, and if you type and save the following info:
dispatch.rb
dispatch.cgi
dispatch.fcgisvn update public/svn commit -m"Ignoring dispatch.* files"That should be that, so that now when I initially check out the project on whatever machine, I just need to create the dispatch.(star) files from the samples, make sure the shebang line is correct, and away I go.
This is spelled out here:
http://subversion.tigris.org/faq.html#website-auto-update
The solution requires three steps:
I’m using this script to initialize a subversioned rails trunk. Maybe it’s useful.
somebody, please review and respond to olegf, if it’s working (not working) for you
Sometimes you want to use plugins for your Rails app. This is how you add them into your project as svn externals.
ruby script/plugin install -x svn_url_to_plugin_repository
svn commit -m "added plugin xxx"
Now this plugin will be checked out into app/vendor/plugins/ and added to your repository as external dependency.
Next time you run
svn update plugin code will be updated from its repository too.
You may want to disable this behaviour and specify the revision for the plugin you want. This is done by
svn propedit svn:externals vendor/plugins
And add revision number after the name of the plugin, like
globalize -r179 svn_url_to_plugin_repository
——
I documented how I create a Rails app and set up SVN revisioning on it over at my website. It’s a fairly straight-forward walkthrough that works well for me so far. YMMV.—GarrettMurray
Creating a New Rails App with SVN
——
I’ve created a ruby script (with the great help of seb and technoweenie) that can be used instead of the rails command to create your application AND import it into the repository “the subversion way”, ignoring various files as per steps 1-10 above (with the exception of #9). For the sake of keeping things DRY, you can find the latest version here: Create a Rails project skeleton and import and checkout from svn all at one
Scroll down to the bottom for the latest version. Use it and change it as much as you like, but post your changes so that I can benefit ;)
My ruby kung-fu is weak, so this code could probably use a good refactoring. Also, as the code is right now, you can’t use the same arguments you do for the regular rails command. Use the rails weenie site (where the code is) to comment and or suggest improvements and or update the code.
——
I spent some time poking around here to figure out how to make my own subversion repository for my rails projects — I’ve compiled what I found from various sources for those who are interested in ssh+svn.
Connecting to your remote SVN repository securely
——
Yet Another Rails + Subversion page.