Skip to content

Instantly share code, notes, and snippets.

@hkraji
Created February 28, 2014 12:33
Show Gist options
  • Save hkraji/9270298 to your computer and use it in GitHub Desktop.
Save hkraji/9270298 to your computer and use it in GitHub Desktop.
Clean and Update all
#!/usr/bin/env ruby
require 'pp'
# no stdout buffering
STDOUT.sync = true
# checks for windows/unix for chaining commands
OS_COMMAND_CHAIN = RUBY_PLATFORM =~ /mswin|mingw|cygwin/ ? "&" : ";"
Dir.entries('.').select do |entry|
next if %w{. .. ,,}.include? entry
if File.directory? File.join('.', entry)
if File.directory? File.join('.', entry, '.git')
full_path = "#{Dir.pwd}/#{entry}"
git_dir = "--git-dir=#{full_path}/.git --work-tree=#{full_path}"
puts "\nUPDATING '#{full_path}' \n\n"
puts `git #{git_dir} clean -f #{OS_COMMAND_CHAIN} git #{git_dir} checkout . #{OS_COMMAND_CHAIN} git #{git_dir} pull origin master`
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment