Created
July 3, 2010 05:16
-
-
Save nas/462335 to your computer and use it in GitHub Desktop.
Automate git pulling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby -swI . | |
# | |
# AUTOMATE UPDATING ALL PROJECTS | |
# | |
# Problem: going to each project and then pulling changes. | |
# Solution: Automate git pulling for all my projects | |
# | |
# 1. Create a pull_projects file and add the code from this gist | |
# 2. Move the file into a directory that is in your path, i.e. $PATH | |
# 3. Make the file executable, eg. chmod +x /usr/local/bin/pull_projects | |
# 4. Run e.g. pull_projects dir1_with_projects dir2_with_projects | |
# 5. Optional: run this on terminal startup so you dont even have to do it manually | |
if ARGV.length == 0 | |
raise "You must specify atleast one project directory to pull changes from remote repository" | |
end | |
ARGV.each do |projects_dir| | |
puts "Starting to pull projects in #{projects_dir}\n" | |
dirs = Dir.entries projects_dir | |
dirs.reject!{|entry| entry.match(/^\./)} | |
dirs.each do |entry| | |
full_dir_path = "#{projects_dir}/#{entry}" | |
if File.directory? full_dir_path | |
Dir.chdir(full_dir_path) | |
check_diff = `git diff` | |
# Don't pull if I have local changes | |
unless check_diff.match(/^$/) | |
puts "You have pending changes in #{entry}" | |
else | |
puts "PULLING #{entry}....\n" | |
system "git pull" | |
end | |
Dir.chdir('../') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice :). thank you.
but I am using windows platform, maybe need to test run on my windows first.
anyway, thank you.