Ruby script for creating new rails project and initial SVN import (with ignoring/removing log/other files)

Published on Author Akhil Bansal11 Comments

Some days go I wrote a bash script for creating new rails project and initial SVN import (with ignoring/removing log/other files). And I received many comments if I could write a ruby script for this stuff. Hence here is the ruby script for creating new rails project and initial SVN import (with ignoring/removing log/other files). Copy this script to any of your directory as “create_rails_with_subversion.rb” and execute by issuing “ruby create_rails_with_subversion.rb ”
You may need command line subversion for windows.

I have tested it at my windows and linux machine, if it not work for you please let me know.

Also I love to have your comments…. :)

11 Responses to Ruby script for creating new rails project and initial SVN import (with ignoring/removing log/other files)

  1. If you put a shebang at the top of the file then it won’t require the .rb extension or need to be run by Ruby when it’s on a *nix system.
    #!/usr/bin/env ruby

    Thanks for this!

  2. Nice script! There is a small bug in the handling of the ‘tmp’ directory, which can be easily corrected:

    Add the following line to the top of the file:
    require ‘find’

    Then, replace these lines…

    system(“svn commit -m \”removing the temp directory from subversion \” “)
    puts “Ignoring tmp dir”
    system(“svn propset svn:ignore \”*\” tmp”+s)
    puts “Updating and commiting again….”
    system(“svn update tmp”+s)
    system(“svn commit -m \”Ignore the whole tmp”+s+” directory, might not work on subdirectories? \” “)
    …with these lines:

    # Traverse the “tmp” subtree, ignoring directories which start with “.”,
    # marking any remaining directories with a property to ignore all files,
    # and removing any files therein from subversion.
    Find.find(“tmp”) do |path|
    if FileTest.directory?(path)
    if File.basename(path)[0] == ?.
    Find.prune # Skip this directory (e.g. “..”, “.svn”)
    else
    # Tell subversion to ignore all files in this directory.
    system(“svn propset svn:ignore \”*\” “+path)
    end
    else
    # Remove any files from subversion.
    system(“svn remove “+path)
    end
    end
    system(“svn commit -m \”removing the tmp subtree from subversion \” “)

    …and the tmp subtree will be properly excluded from subversion.

    The problem was that the old code was not marking subdirectories of ‘tmp’ with the svn:ignore property. The new code removes any stray files under tmp, and marks the ‘tmp’ directory and all subdirectories of ‘tmp’ with the svn:ignore property.

Leave a Reply

Your email address will not be published. Required fields are marked *