Skip to content

Instantly share code, notes, and snippets.

@dinomite
Created February 11, 2011 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinomite/822530 to your computer and use it in GitHub Desktop.
Save dinomite/822530 to your computer and use it in GitHub Desktop.
Perform a git action on a set of subdirectories
#!/usr/bin/env perl
# Drew Stephens <drew@dinomite.net>
# 2011-02-11
#
# Perform an action on all Git repos given on the command line, or globbed.
#
# Check the status of all Git repos in this directory:
# gitall.pl status
#
# Check the status of the Git repos "foo" and "bar" in this directory:
# gitall.pl status foo bar
use strict;
use warnings;
my $gitCommand = $ARGV[0];
my @dirs;
# Get any dirs passed on the command line
print "ARGV count: $#ARGV\n";
foreach (my $x = 1; $x <= $#ARGV; $x++) {
push @dirs, $ARGV[$x];
}
# Fill dirs if none were passed
if ($#dirs == -1) {
@dirs = glob '*';
}
foreach my $dir (@dirs) {
# Skip things that aren't git repos
next if ! -d $dir;
next if ! -d "$dir/.git";
print "Performing <git $gitCommand> in $dir\n";
system("GIT_DIR=$dir/.git GIT_WORK_TREE=$dir git $gitCommand");
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment