Do you have a directory full of checkouts of other people’s projects? For reference, for contribution work, etc?
Wouldn’t you like to update them all at once?
Here’s a basic ruby script that you should run at the root level of your “sources” directory. It will go through the directory, find all the folders, check if they’re under source control (supports svn, git and bzr) and if so, attempts to update them.
It’s not very nice to look at, but it’s saved me a lot of time, and I can’t find anything similar around so I thought I’d release it here. Please tell me if you have any suggestions or improvements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#!/usr/bin/env ruby # Basic script to walk through all directories in a folder and perform an "scm up" on them. # Supports svn, git and bzr # Copyright (c) 2008 Sho Fukamachi # Released under MIT License: http://www.opensource.org/licenses/mit-license.php require 'pathname' def execute(*cmd) begin cmd.flatten! $stdout.puts "executing: " + cmd.join(' ') system(*cmd) unless $?.success? fail "Command failed: " + cmd.join(' ') << else << end rescue RuntimeError puts "!!! command '#{cmd.join(' ')}' failed in #{}, retry manually?" << end end = ENV['PWD'] = Dir.entries() # very dumb, basically an ls -la = [] = [] = [] def purge_invisible dirlist dirlist.delete_if do |entry| entry[0] == 46 # 46 is the hex number for fullstop end end def check_directories dirlist dirlist.delete_if do |entry| !FileTest.directory?(entry) end end purge_invisible check_directories puts "found directories: " + .join(' ') def update_recursively dirlist dirlist.each do |path| = path Dir.chdir path if File::exists?('.svn') puts 'svn detected in ' + path execute 'svn', 'up' elsif File::exists?('.git') puts 'git detected in ' + path execute 'git', 'pull' elsif File::exists?('.bzr') puts 'bazaar dected in ' + path execute 'bzr', 'pull' else << path end Dir.chdir end end update_recursively puts puts "updated in: " + .join(' ') if puts puts "failed in: " + .join(' ') if puts puts "unsupported: " + .join(' ') if puts puts 'done!' |
I know you might think it’s strange to put a copyright license on such a small script but it’s for your protection, not mine. I’ve seen copyright claims over lesser things. By explicitly releasing software code, no matter how simple, you can rest easy in its use anywhere. I wish everyone included licenses with everything; I’d feel a lot more comfortable using things I find on the net if it’s been explicitly released in this manner.