Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created June 5, 2012 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2873606 to your computer and use it in GitHub Desktop.
Save anonymous/2873606 to your computer and use it in GitHub Desktop.
A short ruby script for running status/fetch on multiple repositories
# Installation:
# Add the following to your .bashrc
#
# alias gitall='ruby ~/devel/git_all/git_all.rb'
#
# Usage:
#
# gitall status
# gitall fetch
#
# projects.yml structure:
#
# <project_name>:
# dir: <project path on local>
# remotes: <array of origins>
#
# eg:
#
# git_all:
# dir: /Users/harbogast/devel/git_all
# remotes: macbook
#
# big_project:
# dir: /Users/harbogast/devel/big_project
# remotes: [origin, github, macbook]
#
# Sample output from 'gitall status'
# ================================================================================
# Project: git_all
# cd /Users/harbogast/devel/git_all
# --------------------------------------------------
# git status
# # On branch master
# # Changes not staged for commit:
# # (use "git add <file>..." to update what will be committed)
# # (use "git checkout -- <file>..." to discard changes in working directory)
# #
# # modified: git_all.rb
# #
# no changes added to commit (use "git add" and/or "git commit -a")
# #
#
# Sample output from 'gitall fetch'
# ================================================================================
# Project: big_project
# cd /Users/harbogast/devel/big_project
# --------------------------------------------------
# git fetch origin
# remote: Counting objects: 13, done.
# remote: Compressing objects: 100% (7/7), done.
# remote: Total 8 (delta 1), reused 0 (delta 0)
# Unpacking objects: 100% (8/8), done.
# From git.workrepo.com:big_project
# 00aa670..442b1c4 live -> origin/live
# 9aaf839..442b1c4 master -> origin/master
# 9aaf839..442b1c4 staging -> origin/staging
# * [new tag] rel_00060_20120531090739_staging -> rel_00060_20120531090739_staging
# * [new tag] rel_00061_20120531090856_live -> rel_00061_20120531090856_live
# --------------------------------------------------
# git fetch macbook
# From macbook.harbogast.local:/Users/harbogast/devel/work/big_project
# 73a0885..442b1c4 live -> macbook/live
# bac2c2e..442b1c4 master -> macbook/master
# 87bc16d..442b1c4 staging -> macbook/staging
#
#
# Note: The 'cd /Users/harbogast/devel/git_all' line is output to allow for a quick and dirty
# triple-click/copy/new-tab/paste for jumping into a project directory to do a merge or rebase
require 'yaml'
require 'fileutils'
include FileUtils
class GitProjects
def initialize
@projects = YAML::load( File.open( File.dirname(__FILE__)+'/projects.yml' ) )
@project_names = []
@projects.each do |name, project|
@project_names << name
end
@project_names.sort!
end
def status params=[]
@project_names.each do |name|
project = @projects[name]
heavy_line
project_settings name, project
cd(project['dir'])
thin_line
cd(project['dir'])
ex("git status")
end
heavy_line
end
def fetch remotes=[]
@project_names.each do |name|
project = @projects[name]
heavy_line
project_settings name, project
cd(project['dir'])
if remotes == []
project['remotes'].each do |remote|
thin_line
ex("git fetch #{remote}")
end
else
remotes.each do |remote|
thin_line
ex("git fetch #{remote}")
end
end
end
heavy_line
end
protected
def ex command
log command
system(command)
end
def log str
puts str
end
def project_settings name, project
if project['dir'].nil?
raise Exception.new "project directory not set for #{name}"
end
log "Project: #{name}"
log "cd #{project['dir']}"
end
def thin_line
log "-"*50
end
def heavy_line
log "="*80
end
end
gp = GitProjects.new
gp.send ARGV[0], ARGV[1..-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment