summaryrefslogtreecommitdiff
blob: dd4149547b3a905b76f82ffc46a7071fe9ee79c3 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl

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

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

The following 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
    post-compile                run a post-compile command

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

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

use FindBin;

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

use strict;
use warnings;

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

my ( $command, @args ) = @ARGV;
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 'post-compile' ) {
    post_compile(@args);

} elsif ( -x "$rc{GL_BINDIR}/commands/$command" ) {
    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-/ ) {
    require Gitolite::Conf::Load;
    Gitolite::Conf::Load->import;
    my $fn = lister_dispatch($command);
    print "$_\n" for ( @{ $fn->(@args) } );

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

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

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

=for post_compile
Usage:  gitolite post-compile [-l] [post-compile-scriptname] [script args...]

    -l          list currently available post-compile scripts

Run a post-compile script (which normally runs from the post-update hook in
the gitolite-admin repo).
=cut

sub post_compile {
    usage() if ( not @_ or $_[0] eq '-h' );

    run_subdir( 'post-compile', @_ );
}

sub run_command {
    run_subdir( 'commands', @_ );
}

sub run_subdir {
    my $subdir = shift;
    if ( @_ and $_[0] eq '-l' ) {
        _chdir("$ENV{GL_BINDIR}/$subdir");
        map { say2($_) } grep { -x } glob("*");
        exit 0;
    }

    my $pgm      = shift;
    my $fullpath = "$ENV{GL_BINDIR}/$subdir/$pgm";
    _die "$pgm not found or not executable" if not -x $fullpath;
    _system( $fullpath, @_ );
    exit 0;
}