summaryrefslogtreecommitdiffstats
path: root/src/gitolite
blob: c11e047ddfd06d27c75a96d959c0009e6708979d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl

# all gitolite CLI tools run as sub-commands of this command
# ----------------------------------------------------------------------

=for args
Usage:  gitolite [sub-command] [options]

The following built-in subcommands are available; they should all respond to
'-h' if you want further details on each:

    setup                       1st run: initial setup; all runs: hook fixups
    compile                     compile gitolite.conf

    query-rc                    get values of rc variables

    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'

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.
=cut

# ----------------------------------------------------------------------

use FindBin;

BEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin; }
BEGIN { $ENV{GL_LIBDIR} = "$ENV{GL_BINDIR}/lib"; }
use lib $ENV{GL_LIBDIR};
use Gitolite::Rc;
use Gitolite::Common;

use strict;
use warnings;

# ----------------------------------------------------------------------

my ( $command, @args ) = @ARGV;
gl_log( 'cli', 'gitolite', @ARGV ) if -d $rc{GL_ADMIN_BASE} and $$ == ( $ENV{GL_TID} || 0 );
args();

# 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);

} elsif ( $command eq 'trigger' ) {
    my $s = $args[0];
    _die "trigger section '$s' not found in rc"
        unless  $s eq 'POST_COMPILE'
             or $s eq 'POST_CREATE'
             or ( exists $rc{$s} and ref( $rc{$s} ) eq 'ARRAY' );
    trigger(@args);

} elsif ( my $c = _which( "commands/$command", 'x' ) ) {
    trace( 2, "attempting gitolite command $c" );
    _system( $c, @args );

} elsif ( $command eq 'list-phy-repos' ) {
    _chdir( $rc{GL_REPO_BASE} );
    print "$_\n" for ( @{ list_phy_repos(@args) } );

} elsif ( $command =~ /^list-/ ) {
    trace( 2, "attempting lister command $command" );
    require Gitolite::Conf::Load;
    Gitolite::Conf::Load->import;
    my $fn = lister_dispatch($command);
    print "$_\n" for ( @{ $fn->(@args) } );

} else {
    _die "unknown gitolite sub-command";
}

gl_log('END') if $$ == $ENV{GL_TID};

exit 0;

sub args {
    usage() if not $command or $command eq '-h';
}

# ----------------------------------------------------------------------