'perms' command learns to create repo if needed

This commit is contained in:
Sitaram Chamarty 2012-06-01 09:52:12 +05:30
parent d9df70a04f
commit 42e0bac48c
2 changed files with 48 additions and 3 deletions

View file

@ -21,12 +21,21 @@ Examples:
ssh git@host perms foo + READERS user2
ssh git@host perms foo + READERS user3
(Note: a legacy mode of piping in the entire permissions text directly is also
supported. If you want to use it, don't mix it with the new "+/-" modes).
----
There is also a batch mode useful for scripting and bulk loading. Do not
combine this with the +/- mode above. This mode also accepts an optional "-c"
flag to create the repo if it does not already exist (assuming $GL_USER has
permissions to create it).
Examples:
cat copy-of-backed-up-gl-perms | ssh git@host perms <repo>
cat copy-of-backed-up-gl-perms | ssh git@host perms -c <repo>
=cut
usage() if not @ARGV or $ARGV[0] eq '-h';
$ENV{GL_USER} or _die "GL_USER not set";
my $list = 0;
if ( $ARGV[0] eq '-l' ) {
$list++;
@ -34,6 +43,23 @@ if ( $ARGV[0] eq '-l' ) {
getperms(@ARGV); # doesn't return
}
# auto-create the repo if -c passed and repo doesn't exist
if ( $ARGV[0] eq '-c' ) {
shift;
my $repo = $ARGV[0];
_die "invalid repo '$repo'" unless $repo =~ $REPONAME_PATT;
if (not -d "$rc{GL_REPO_BASE}/$repo.git") {
my $ret = access( $repo, $ENV{GL_USER}, '^C', 'any' );
_die $ret if $ret =~ /DENIED/;
require Gitolite::Conf::Store;
Gitolite::Conf::Store->import;
new_wild_repo( $repo, $ENV{GL_USER} );
gl_log( 'create', $repo, $ENV{GL_USER} );
}
}
my $repo = shift;
setperms(@ARGV);
_system( "gitolite", "trigger", "POST_CREATE", $repo, $ENV{GL_USER} );

View file

@ -9,7 +9,7 @@ use Gitolite::Test;
# uhh, seems to be another rule sequence test
# ----------------------------------------------------------------------
try "plan 40";
try "plan 48";
confreset;confadd '
@staff = u1 u2 u3
@ -61,6 +61,7 @@ confreset;confadd '
RW+ = CREATOR
- = @staff
RW = WRITERS
R = READERS
';
try "ADMIN_PUSH set1; !/FATAL/" or die text();
@ -81,6 +82,7 @@ try "
/WRITERS u2/
# expand
glt info u2
!/R W *\tfoo/u1/baz/
/R W *\tfoo/u1/bar/
/R W *\ttesting/
@ -94,4 +96,21 @@ try "
!ok
reject
/W refs/heads/master foo/u1/bar u2 DENIED by refs/\\.\\*/
# auto-create using perms fail
echo READERS u5 | glt perms u4 -c foo/u4/baz
!/Initialized empty Git repository in .*/foo/u4/baz.git/
/FATAL: .C any foo/u4/baz u4 DENIED by fallthru/
# auto-create using perms
echo READERS u2 | glt perms u1 -c foo/u1/baz
/Initialized empty Git repository in .*/foo/u1/baz.git/
glt perms u1 -l foo/u1/baz
/READERS u2/
# expand
glt info u2
/R *\tfoo/u1/baz/
/R W *\tfoo/u1/bar/
/R W *\ttesting/
";