Created
September 21, 2013 02:25
-
-
Save mlbright/6646553 to your computer and use it in GitHub Desktop.
list all git repos in a directory
This file contains hidden or 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 | |
use strict; | |
use warnings; | |
use File::Find; | |
my $root = '/git'; | |
my %gitdir = map { $_ => 1 } qw( | |
branches | |
config | |
description | |
HEAD | |
hooks | |
info | |
objects | |
refs | |
); | |
my %repos; | |
find( | |
sub { | |
my $dh; | |
opendir( $dh, $File::Find::dir ) | |
|| die "Can't open " . $File::Find::dir . ": $!\n"; | |
my %entries = map { $_ => 1 } readdir($dh); | |
closedir $dh; | |
my $isgit = 1; | |
for ( keys %gitdir ) { | |
unless ( exists( $entries{$_} ) ) { | |
$isgit = 0; | |
last; | |
} | |
} | |
if ($isgit) { | |
$repos{$File::Find::dir} = 1; | |
$File::Find::prune = 1; | |
} | |
}, | |
$root | |
); | |
for ( sort keys %repos ) { | |
print $_ . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment