Skip to content

Instantly share code, notes, and snippets.

@mshroyer
Created March 28, 2013 22:25
Show Gist options
  • Select an option

  • Save mshroyer/5267342 to your computer and use it in GitHub Desktop.

Select an option

Save mshroyer/5267342 to your computer and use it in GitHub Desktop.
gitolite fsck command
#!/usr/bin/env perl
# gitolite fsck command
#
# Add this to the gitolite commands subdirectory (e.g. on FreeBSD,
# /usr/libexec/gitolite/commands/) and then invoke `gitolite fsck` to run
# integrity checks on your repositories.
#
# Mark Shroyer
# Thu Mar 28 12:16:12 EDT 2013
use warnings;
use strict;
use lib $ENV{GL_LIBDIR};
use Gitolite::Easy;
use Gitolite::Rc;
use Gitolite::Common;
=for usage
Usage: gitolite fsck <reponame>|@all
Runs git fsck on all repos or the named repo. It's probably a good idea to
run this periodically in order to avoid a "Too Perfect a Mirror" scenario.
=cut
usage() if not @ARGV or @ARGV < 1 or $ARGV[0] eq '-h';
my $all = ( $ARGV[0] eq '@all' );
open(STDERR, ">&STDOUT") or _die "Can't dup STDOUT";
my @repos;
if ( $all ) {
_die "you are not authorized" if $ENV{GL_USER} and not is_admin();
chdir $rc{GL_REPO_BASE};
@repos = @{ list_phy_repos() };
} else {
my $repo = shift @ARGV;
_die "you are not authorized" if $ENV{GL_USER} and not (is_admin() or owns($repo));
@repos = ( $repo );
}
for my $repo ( @repos ) {
chdir "$rc{GL_REPO_BASE}/${repo}.git" or _die "$repo does not exist";
print "fsck repository: $repo\n";
system("git fsck --progress") == 0 or _die "fsck failed for $repo";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment