new mirror function: 'status all all'
[gitolite.git] / src / commands / git-config
blob94211de58ed54af9c492f5af61afb100c2d203f9
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use Getopt::Long;
6 use lib $ENV{GL_LIBDIR};
7 use Gitolite::Rc;
8 use Gitolite::Common;
9 use Gitolite::Conf::Load;
11 =for usage
12 Usage: gitolite git-config [-n] [-q] [-r] <repo> <key|pattern>
14 Print git config keys and values for the given repo. The key is either a full
15 key, or, if '-r' is supplied, a regex that is applied to all available keys.
17 -q exit code only (shell truth; 0 is success)
18 -n suppress trailing newline when used as key (not pattern)
19 -r treat key as regex pattern (unanchored)
20 -ev print keys with empty values also (see below)
22 Examples:
23 gitolite git-config repo gitweb.owner
24 gitolite git-config -q repo gitweb.owner
25 gitolite git-config -r repo gitweb
27 Notes:
29 1. When the key is treated as a pattern, prints:
31 reponame<tab>key<tab>value<newline>
33 Otherwise the output is just the value.
35 2. By default, keys with empty values (specified as "" in the conf file) are
36 treated as non-existant. Using '-ev' will print those keys also. Note
37 that this only makes sense when the key is treated as a pattern, where
38 such keys are printed as:
40 reponame<tab>key<tab><newline>
42 3. Finally, see the advanced use section of 'gitolite access -h' -- you can
43 do something similar here also:
45 gitolite list-phy-repos | gitolite git-config -r % gitweb\\. | cut -f1 > ~/projects.list
46 =cut
48 usage() if not @ARGV;
50 my ( $help, $nonl, $quiet, $regex, $ev ) = (0) x 5;
51 GetOptions(
52 'n' => \$nonl,
53 'q' => \$quiet,
54 'r' => \$regex,
55 'h' => \$help,
56 'ev' => \$ev,
57 ) or usage();
59 my ( $repo, $key ) = @ARGV;
60 usage() unless $key;
62 my $ret = '';
64 if ( $repo ne '%' and $key ne '%' ) {
65 # single repo, single key; no STDIN
66 $key = "^\Q$key\E\$" unless $regex;
68 $ret = git_config( $repo, $key, $ev );
70 # if the key is not a regex, it should match at most one item
71 _die "found more than one entry for '$key'" if not $regex and scalar( keys %$ret ) > 1;
73 # unlike access, there's nothing to print if we don't find any matching keys
74 exit 1 unless %$ret;
76 if ($regex) {
77 map { print "$repo\t$_\t" . $ret->{$_} . "\n" } sort keys %$ret unless $quiet;
78 } else {
79 map { print $ret->{$_} . ( $nonl ? "" : "\n" ) } sort keys %$ret unless $quiet;
81 exit 0;
84 $repo = '' if $repo eq '%';
85 $key = '' if $key eq '%';
87 _die "'-q' doesn't go with using a pipe" if $quiet;
88 @ARGV = ();
89 while (<>) {
90 my @in = split;
91 my $r = $repo || shift @in;
92 my $k = $key || shift @in;
93 $k = "^\Q$k\E\$" unless $regex;
94 $ret = git_config( $r, $k, $ev );
95 next unless %$ret;
96 map { print "$r\t$_\t" . $ret->{$_} . "\n" } sort keys %$ret;