Skip to content

Instantly share code, notes, and snippets.

@mlbright
Created September 21, 2013 02:25
Show Gist options
  • Save mlbright/6646553 to your computer and use it in GitHub Desktop.
Save mlbright/6646553 to your computer and use it in GitHub Desktop.
list all git repos in a directory
#!/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