info command simplified
(thanks to Eli for the back-and-forth that led to this)
This commit is contained in:
parent
ae75f9c938
commit
dfb9844dfb
|
@ -9,63 +9,73 @@ use Gitolite::Rc;
|
||||||
use Gitolite::Common;
|
use Gitolite::Common;
|
||||||
use Gitolite::Conf::Load;
|
use Gitolite::Conf::Load;
|
||||||
|
|
||||||
=for usage
|
=for args
|
||||||
Usage: gitolite info [-p [-lc] [<repo name pattern>]
|
Usage: gitolite info [-lc] [<repo name pattern>]
|
||||||
|
|
||||||
List all repos/repo groups you can access. By default, it shows you what the
|
List all repos/repo groups you can access.
|
||||||
conf file specified, which means group names and wild card patterns may show
|
|
||||||
up. Example, if the conf file looked like this:
|
|
||||||
|
|
||||||
@oss = git gitolite linux
|
'-lc' lists creators as an additional field at the end.
|
||||||
repo @oss
|
|
||||||
RW+ = YourName
|
|
||||||
|
|
||||||
then running 'ssh git@host info' will only show you '@oss'.
|
|
||||||
|
|
||||||
'-p' looks at actual (physical) repos instead; in our example this will show
|
|
||||||
you git, gitolite, and linux.
|
|
||||||
|
|
||||||
'-lc' lists creators as an additional field at the end; this option is only
|
|
||||||
available with '-p'.
|
|
||||||
|
|
||||||
The optional pattern is an unanchored regex that will limit the repos
|
The optional pattern is an unanchored regex that will limit the repos
|
||||||
searched, in both cases. It might speed up things a little if you have more
|
searched, in both cases. It might speed up things a little if you have more
|
||||||
than a few thousand repos.
|
than a few thousand repos.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
my ( $help, $phy, $lc, $patt ) = ('') x 4;
|
# these two are globals
|
||||||
|
my ( $lc, $patt ) = args();
|
||||||
|
|
||||||
|
print_version();
|
||||||
|
|
||||||
|
print_patterns(); # repos he can create for himself
|
||||||
|
print_phy_repos(); # repos already created
|
||||||
|
print "\n$rc{SITE_INFO}\n" if $rc{SITE_INFO};
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
sub args {
|
||||||
|
my ( $lc, $patt ) = ( '', '' );
|
||||||
|
my $help = '';
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
'lc' => \$lc,
|
'lc' => \$lc,
|
||||||
'p' => \$phy,
|
|
||||||
'h' => \$help,
|
'h' => \$help,
|
||||||
) or usage();
|
) or usage();
|
||||||
|
|
||||||
usage("'-lc' requires '-p'") if $lc and not $phy;
|
|
||||||
usage() if @ARGV > 1 or $help;
|
usage() if @ARGV > 1 or $help;
|
||||||
$patt = shift || '.';
|
$patt = shift @ARGV || '.';
|
||||||
|
|
||||||
my $user = $ENV{GL_USER} or _die "GL_USER not set";
|
return ( $lc, $patt );
|
||||||
my $ref = 'any';
|
}
|
||||||
|
|
||||||
|
sub print_version {
|
||||||
chomp( my $hn = `hostname -s` );
|
chomp( my $hn = `hostname -s` );
|
||||||
my $gv = substr( `git --version`, 12 );
|
my $gv = substr( `git --version`, 12 );
|
||||||
print "hello $user, this is $ENV{USER}\@$hn running gitolite3 " . version() . " on git $gv\n";
|
$ENV{GL_USER} or _die "GL_USER not set";
|
||||||
|
print "hello $ENV{GL_USER}, this is $ENV{USER}\@$hn running gitolite3 " . version() . " on git $gv\n";
|
||||||
|
}
|
||||||
|
|
||||||
my $lr = lister_dispatch('list-repos');
|
sub print_patterns {
|
||||||
|
my ( $repos, @aa );
|
||||||
|
|
||||||
my $perm;
|
# find repo patterns only, call them with ^C flag included
|
||||||
my $repos;
|
@$repos = grep { !/$REPONAME_PATT/ } @{ lister_dispatch('list-repos')->() };
|
||||||
my @aa;
|
@aa = qw(R W ^C);
|
||||||
|
listem( $repos, '', @aa );
|
||||||
|
# but squelch the 'lc' flag for these
|
||||||
|
}
|
||||||
|
|
||||||
if ($phy) {
|
sub print_phy_repos {
|
||||||
|
my ( $repos, @aa );
|
||||||
|
|
||||||
|
# now get the actual repos and get R or W only
|
||||||
_chdir( $rc{GL_REPO_BASE} );
|
_chdir( $rc{GL_REPO_BASE} );
|
||||||
$repos = list_phy_repos(1);
|
$repos = list_phy_repos(1);
|
||||||
@aa = qw(R W);
|
@aa = qw(R W);
|
||||||
} else {
|
listem( $repos, $lc, @aa );
|
||||||
$repos = $lr->();
|
|
||||||
@aa = qw(R W ^C);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub listem {
|
||||||
|
my ( $repos, $lc, @aa ) = @_;
|
||||||
my $creator = '';
|
my $creator = '';
|
||||||
for my $repo (@$repos) {
|
for my $repo (@$repos) {
|
||||||
next unless $repo =~ /$patt/;
|
next unless $repo =~ /$patt/;
|
||||||
|
@ -73,7 +83,7 @@ for my $repo (@$repos) {
|
||||||
$creator = creator($repo) if $lc;
|
$creator = creator($repo) if $lc;
|
||||||
|
|
||||||
for my $aa (@aa) {
|
for my $aa (@aa) {
|
||||||
my $ret = access( $repo, $user, $aa, $ref );
|
my $ret = access( $repo, $ENV{GL_USER}, $aa, 'any' );
|
||||||
$perm .= ( $ret =~ /DENIED/ ? " " : " $aa" );
|
$perm .= ( $ret =~ /DENIED/ ? " " : " $aa" );
|
||||||
}
|
}
|
||||||
$perm =~ s/\^//;
|
$perm =~ s/\^//;
|
||||||
|
@ -82,5 +92,5 @@ for my $repo (@$repos) {
|
||||||
print "\t$creator" if $lc;
|
print "\t$creator" if $lc;
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print "\n$rc{SITE_INFO}\n" if $rc{SITE_INFO};
|
|
||||||
|
|
83
t/info.t
83
t/info.t
|
@ -9,7 +9,7 @@ use Gitolite::Test;
|
||||||
# the info command
|
# the info command
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
try 'plan 83';
|
try 'plan 78';
|
||||||
|
|
||||||
try "## info";
|
try "## info";
|
||||||
|
|
||||||
|
@ -24,6 +24,10 @@ confreset;confadd '
|
||||||
repo t3
|
repo t3
|
||||||
RW = u3
|
RW = u3
|
||||||
R = u4
|
R = u4
|
||||||
|
|
||||||
|
repo foo/..*
|
||||||
|
C = u1
|
||||||
|
RW = CREATOR u3
|
||||||
';
|
';
|
||||||
|
|
||||||
try "ADMIN_PUSH info; !/FATAL/" or die text();
|
try "ADMIN_PUSH info; !/FATAL/" or die text();
|
||||||
|
@ -38,66 +42,67 @@ try "DEF GS = /hello %1, this is $ENV{USER}\\@.* running gitolite/";
|
||||||
|
|
||||||
try "
|
try "
|
||||||
glt info u1; ok; GS u1
|
glt info u1; ok; GS u1
|
||||||
/R W \t\@t1/
|
/C\tfoo/\\.\\.\\*/
|
||||||
/R \tt2/
|
|
||||||
/R W \ttesting/
|
|
||||||
!/R W \tt3/
|
|
||||||
glt info u2; ok; GS u2
|
|
||||||
/R \t\@t1/
|
|
||||||
/R W \tt2/
|
|
||||||
/R W \ttesting/
|
|
||||||
!/R W \tt3/
|
|
||||||
glt info u3; ok; GS u3
|
|
||||||
/R W \tt3/
|
|
||||||
/R W \ttesting/
|
|
||||||
!/R \t\@t1/
|
|
||||||
!/R W \tt2/
|
|
||||||
glt info u4; ok; GS u4
|
|
||||||
/R \tt3/
|
|
||||||
/R W \ttesting/
|
|
||||||
!/R \t\@t1/
|
|
||||||
!/R W \tt2/
|
|
||||||
glt info u5; ok; GS u5
|
|
||||||
/R W \ttesting/
|
|
||||||
!/R \t\@t1/
|
|
||||||
!/R W \tt2/
|
|
||||||
!/R W \tt3/
|
|
||||||
glt info u6; ok; GS u6
|
|
||||||
/R W \ttesting/
|
|
||||||
!/R \t\@t1/
|
|
||||||
!/R W \tt2/
|
|
||||||
!/R W \tt3/
|
|
||||||
";
|
|
||||||
|
|
||||||
try "
|
|
||||||
glt info u1 -p; ok; GS u1
|
|
||||||
/R W *\tt1/
|
/R W *\tt1/
|
||||||
/R *\tt2/
|
/R *\tt2/
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
!/R W *\tt3/
|
!/R W *\tt3/
|
||||||
glt info u2 -p; ok; GS u2
|
glt info u2; ok; GS u2
|
||||||
|
!/C\tfoo/
|
||||||
/R *\tt1/
|
/R *\tt1/
|
||||||
/R W *\tt2/
|
/R W *\tt2/
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
!/R W *\tt3/
|
!/R W *\tt3/
|
||||||
glt info u3 -p; ok; GS u3
|
glt info u3; ok; GS u3
|
||||||
/R W *\tt3/
|
/R W *\tt3/
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
!/R *\tt1/
|
!/R *\tt1/
|
||||||
!/R W *\tt2/
|
!/R W *\tt2/
|
||||||
glt info u4 -p; ok; GS u4
|
glt info u4; ok; GS u4
|
||||||
/R *\tt3/
|
/R *\tt3/
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
!/R *\tt1/
|
!/R *\tt1/
|
||||||
!/R W *\tt2/
|
!/R W *\tt2/
|
||||||
glt info u5 -p; ok; GS u5
|
glt info u5; ok; GS u5
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
!/R *\tt1/
|
!/R *\tt1/
|
||||||
!/R W *\tt2/
|
!/R W *\tt2/
|
||||||
!/R W *\tt3/
|
!/R W *\tt3/
|
||||||
glt info u6 -p; ok; GS u6
|
glt info u6; ok; GS u6
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
!/R *\tt1/
|
!/R *\tt1/
|
||||||
!/R W *\tt2/
|
!/R W *\tt2/
|
||||||
!/R W *\tt3/
|
!/R W *\tt3/
|
||||||
";
|
";
|
||||||
|
|
||||||
|
try "
|
||||||
|
glt ls-remote u1 file:///foo/one; ok
|
||||||
|
glt info u1; ok; GS u1
|
||||||
|
/C\tfoo/\\.\\.\\*/
|
||||||
|
/R W *\tfoo/one/
|
||||||
|
!/R W *\tfoo/one\tu1/
|
||||||
|
glt info u2; ok; GS u2
|
||||||
|
!/C\tfoo/
|
||||||
|
!/R W *\tfoo/one/
|
||||||
|
glt info u3; ok; GS u3
|
||||||
|
!/C\tfoo/
|
||||||
|
/R W *\tfoo/one/
|
||||||
|
!/R W *\tfoo/one\tu1/
|
||||||
|
";
|
||||||
|
|
||||||
|
try "
|
||||||
|
glt ls-remote u1 file:///foo/one; ok
|
||||||
|
glt info u1 -lc; ok; GS u1
|
||||||
|
put
|
||||||
|
/C\tfoo/\\.\\.\\*/
|
||||||
|
!/C\tfoo.*u1/
|
||||||
|
/R W *\tfoo/one\tu1/
|
||||||
|
glt info u2 -lc; ok; GS u2
|
||||||
|
put
|
||||||
|
!/C\tfoo/
|
||||||
|
!/R W *\tfoo/one/
|
||||||
|
glt info u3 -lc; ok; GS u3
|
||||||
|
put
|
||||||
|
!/C\tfoo/
|
||||||
|
/R W *\tfoo/one\tu1/
|
||||||
|
";
|
||||||
|
|
|
@ -33,20 +33,20 @@ try "
|
||||||
glt ls-remote u1 file:///bar/u1/try1
|
glt ls-remote u1 file:///bar/u1/try1
|
||||||
/Initialized empty Git repository in .*/bar/u1/try1.git//
|
/Initialized empty Git repository in .*/bar/u1/try1.git//
|
||||||
# default permissions for u2 and u4
|
# default permissions for u2 and u4
|
||||||
glt info u1 -p -lc
|
glt info u1 -lc
|
||||||
/R W *\tbar/u1/try1\tu1/
|
/R W *\tbar/u1/try1\tu1/
|
||||||
glt info u2 -p -lc
|
glt info u2 -lc
|
||||||
!/R W *\tbar/u1/try1\tu1/
|
!/R W *\tbar/u1/try1\tu1/
|
||||||
glt info u4 -p -lc
|
glt info u4 -lc
|
||||||
!/R W *\tbar/u1/try1\tu1/
|
!/R W *\tbar/u1/try1\tu1/
|
||||||
|
|
||||||
# \@leads can RW try1
|
# \@leads can RW try1
|
||||||
echo WRITERS \@leads | glt perms u1 bar/u1/try1; ok
|
echo WRITERS \@leads | glt perms u1 bar/u1/try1; ok
|
||||||
glt info u1 -p -lc
|
glt info u1 -lc
|
||||||
/R W *\tbar/u1/try1\tu1/
|
/R W *\tbar/u1/try1\tu1/
|
||||||
glt info u2 -p -lc
|
glt info u2 -lc
|
||||||
/R W *\tbar/u1/try1\tu1/
|
/R W *\tbar/u1/try1\tu1/
|
||||||
glt info u4 -p -lc
|
glt info u4 -lc
|
||||||
!/R W *\tbar/u1/try1\tu1/
|
!/R W *\tbar/u1/try1\tu1/
|
||||||
|
|
||||||
# \@devs can R try1
|
# \@devs can R try1
|
||||||
|
@ -55,14 +55,14 @@ try "
|
||||||
/READERS \@devs/
|
/READERS \@devs/
|
||||||
!/WRITERS \@leads/
|
!/WRITERS \@leads/
|
||||||
|
|
||||||
glt info u1 -p -lc
|
glt info u1 -lc
|
||||||
/R W *\tbar/u1/try1\tu1/
|
/R W *\tbar/u1/try1\tu1/
|
||||||
|
|
||||||
glt info u2 -p -lc
|
glt info u2 -lc
|
||||||
!/R W *\tbar/u1/try1\tu1/
|
!/R W *\tbar/u1/try1\tu1/
|
||||||
/R *\tbar/u1/try1\tu1/
|
/R *\tbar/u1/try1\tu1/
|
||||||
|
|
||||||
glt info u4 -p -lc
|
glt info u4 -lc
|
||||||
!/R W *\tbar/u1/try1\tu1/
|
!/R W *\tbar/u1/try1\tu1/
|
||||||
/R *\tbar/u1/try1\tu1/
|
/R *\tbar/u1/try1\tu1/
|
||||||
|
|
||||||
|
@ -71,11 +71,11 @@ try "
|
||||||
glt perms u1 -l bar/u1/try1
|
glt perms u1 -l bar/u1/try1
|
||||||
/READERS \@devs/
|
/READERS \@devs/
|
||||||
/WRITERS \@leads/
|
/WRITERS \@leads/
|
||||||
glt info u1 -p -lc
|
glt info u1 -lc
|
||||||
/R W *\tbar/u1/try1\tu1/
|
/R W *\tbar/u1/try1\tu1/
|
||||||
glt info u2 -p -lc
|
glt info u2 -lc
|
||||||
/R W *\tbar/u1/try1\tu1/
|
/R W *\tbar/u1/try1\tu1/
|
||||||
glt info u4 -p -lc
|
glt info u4 -lc
|
||||||
!/R W *\tbar/u1/try1\tu1/
|
!/R W *\tbar/u1/try1\tu1/
|
||||||
/R *\tbar/u1/try1\tu1/
|
/R *\tbar/u1/try1\tu1/
|
||||||
";
|
";
|
||||||
|
|
|
@ -37,7 +37,7 @@ try "
|
||||||
glt perms u1 -l foo/u1/bar
|
glt perms u1 -l foo/u1/bar
|
||||||
/WRITERS u2/
|
/WRITERS u2/
|
||||||
# expand
|
# expand
|
||||||
glt info u2 -p
|
glt info u2
|
||||||
/R W *\tfoo/u1/bar/
|
/R W *\tfoo/u1/bar/
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ try "
|
||||||
glt perms u1 -l foo/u1/bar
|
glt perms u1 -l foo/u1/bar
|
||||||
/WRITERS u2/
|
/WRITERS u2/
|
||||||
# expand
|
# expand
|
||||||
glt info u2 -p
|
glt info u2
|
||||||
/R W *\tfoo/u1/bar/
|
/R W *\tfoo/u1/bar/
|
||||||
/R W *\ttesting/
|
/R W *\ttesting/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue