Created
February 11, 2011 15:50
-
-
Save dinomite/822530 to your computer and use it in GitHub Desktop.
Perform a git action on a set of subdirectories
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/bin/env perl | |
# Drew Stephens <[email protected]> | |
# 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