2012-03-08 09:00:13 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
# all gitolite CLI tools run as sub-commands of this command
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
=for args
|
2012-03-10 14:26:29 +01:00
|
|
|
Usage: gitolite [sub-command] [options]
|
2012-03-08 09:00:13 +01:00
|
|
|
|
2012-03-16 04:55:39 +01:00
|
|
|
The following built-in subcommands are available; they should all respond to
|
|
|
|
'-h' if you want further details on each:
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
setup 1st run: initial setup; all runs: hook fixups
|
|
|
|
compile compile gitolite.conf
|
2012-03-12 16:24:30 +01:00
|
|
|
|
2012-03-08 09:00:13 +01:00
|
|
|
query-rc get values of rc variables
|
2012-03-12 16:24:30 +01:00
|
|
|
|
2012-03-08 09:00:13 +01:00
|
|
|
list-groups list all group names in conf
|
|
|
|
list-users list all users/user groups in conf
|
|
|
|
list-repos list all repos/repo groups in conf
|
|
|
|
list-phy-repos list all repos actually on disk
|
|
|
|
list-memberships list all groups a name is a member of
|
|
|
|
list-members list all members of a group
|
|
|
|
|
|
|
|
Warnings:
|
|
|
|
- list-users is disk bound and could take a while on sites with 1000s of repos
|
|
|
|
- list-memberships does not check if the name is known; unknown names come
|
|
|
|
back with 2 answers: the name itself and '@all'
|
2012-03-16 04:55:39 +01:00
|
|
|
|
|
|
|
In addition, running 'gitolite help' should give you a list of custom commands
|
|
|
|
available. They may or may not respond to '-h', depending on how they were
|
|
|
|
written.
|
2012-03-08 09:00:13 +01:00
|
|
|
=cut
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
use FindBin;
|
|
|
|
|
|
|
|
BEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; }
|
|
|
|
use lib $ENV{GL_BINDIR};
|
|
|
|
use Gitolite::Rc;
|
|
|
|
use Gitolite::Common;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
my ( $command, @args ) = @ARGV;
|
2012-03-17 16:43:28 +01:00
|
|
|
gl_log( 'gitolite', @ARGV ) if -d $rc{GL_ADMIN_BASE};
|
2012-03-08 09:00:13 +01:00
|
|
|
args();
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
# the first two commands need options via @ARGV, as they have their own
|
|
|
|
# GetOptions calls and older perls don't have 'GetOptionsFromArray'
|
|
|
|
|
|
|
|
if ( $command eq 'setup' ) {
|
|
|
|
shift @ARGV;
|
|
|
|
require Gitolite::Setup;
|
|
|
|
Gitolite::Setup->import;
|
|
|
|
setup();
|
|
|
|
|
|
|
|
} elsif ( $command eq 'query-rc' ) {
|
|
|
|
shift @ARGV;
|
|
|
|
query_rc(); # doesn't return
|
|
|
|
|
|
|
|
# the rest don't need @ARGV per se
|
|
|
|
|
|
|
|
} elsif ( $command eq 'compile' ) {
|
|
|
|
require Gitolite::Conf;
|
|
|
|
Gitolite::Conf->import;
|
|
|
|
compile(@args);
|
|
|
|
|
2012-03-16 04:55:39 +01:00
|
|
|
} elsif ( $command eq 'run-all' ) {
|
|
|
|
run_all(@args);
|
2012-03-12 16:24:30 +01:00
|
|
|
|
|
|
|
} elsif ( -x "$rc{GL_BINDIR}/commands/$command" ) {
|
2012-03-15 16:30:39 +01:00
|
|
|
trace( 2, "attempting gitolite command $command" );
|
2012-03-12 16:24:30 +01:00
|
|
|
run_command( $command, @args );
|
|
|
|
|
|
|
|
} elsif ( $command eq 'list-phy-repos' ) {
|
|
|
|
_chdir( $rc{GL_REPO_BASE} );
|
|
|
|
print "$_\n" for ( @{ list_phy_repos(@args) } );
|
|
|
|
|
|
|
|
} elsif ( $command =~ /^list-/ ) {
|
2012-03-15 16:30:39 +01:00
|
|
|
trace( 2, "attempting lister command $command" );
|
2012-03-12 16:24:30 +01:00
|
|
|
require Gitolite::Conf::Load;
|
|
|
|
Gitolite::Conf::Load->import;
|
|
|
|
my $fn = lister_dispatch($command);
|
|
|
|
print "$_\n" for ( @{ $fn->(@args) } );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
_die "unknown gitolite sub-command";
|
|
|
|
}
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
sub args {
|
|
|
|
usage() if not $command or $command eq '-h';
|
|
|
|
}
|
2012-03-11 17:03:15 +01:00
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
sub run_command {
|
|
|
|
my $pgm = shift;
|
2012-03-16 04:55:39 +01:00
|
|
|
my $fullpath = "$ENV{GL_BINDIR}/commands/$pgm";
|
2012-03-11 17:03:15 +01:00
|
|
|
_die "$pgm not found or not executable" if not -x $fullpath;
|
2012-03-12 16:24:30 +01:00
|
|
|
_system( $fullpath, @_ );
|
2012-03-11 17:03:15 +01:00
|
|
|
exit 0;
|
|
|
|
}
|
2012-03-16 04:55:39 +01:00
|
|
|
|
|
|
|
sub run_all {
|
|
|
|
my $rc_section = shift;
|
|
|
|
|
|
|
|
if ( exists $rc{$rc_section} ) {
|
|
|
|
if ( ref( $rc{$rc_section} ) ne 'ARRAY' ) {
|
|
|
|
_warn "$rc_section section in rc file is not a perl list";
|
|
|
|
} else {
|
|
|
|
for my $s ( @{ $rc{$rc_section} } ) {
|
|
|
|
|
|
|
|
# perl-ism; apart from keeping the full path separate from the
|
|
|
|
# simple name, this also protects %rc from change by implicit
|
|
|
|
# aliasing, which would happen if you touched $s itself
|
|
|
|
my $sfp = "$ENV{GL_BINDIR}/commands/$s";
|
|
|
|
|
|
|
|
_warn("skipped command '$s'"), next if not -x $sfp;
|
|
|
|
trace( 2, "command: $s" );
|
|
|
|
_system( $sfp, @ARGV ); # they better all return with 0 exit codes!
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 03:10:17 +01:00
|
|
|
return;
|
2012-03-16 04:55:39 +01:00
|
|
|
}
|
2012-03-17 03:10:17 +01:00
|
|
|
trace( 2, "'$rc_section' not found in rc" );
|
2012-03-16 04:55:39 +01:00
|
|
|
}
|