diff --git a/src/lib/Gitolite/Easy.pm b/src/lib/Gitolite/Easy.pm index 280a924..9231d00 100644 --- a/src/lib/Gitolite/Easy.pm +++ b/src/lib/Gitolite/Easy.pm @@ -112,14 +112,18 @@ sub can_read { } # can_write() -# return true if $ENV{GL_USER} is set and can write to the given repo +# return true if $ENV{GL_USER} is set and can write to the given repo. +# Optional second argument can be '+' to check that instead of 'W'. Optional +# third argument can be a full ref name instead of 'any'. # shell equivalent # if gitolite access -q $REPONAME $GL_USER W; then ... sub can_write { valid_user(); - my $r = shift; - return not( access( $r, $user, 'W', 'any' ) =~ /DENIED/ ); + my ($r, $aa, $ref) = @_; + $aa ||= 'W'; + $ref ||= 'any'; + return not( access( $r, $user, $aa, $ref ) =~ /DENIED/ ); } # config() diff --git a/t/easy.t b/t/easy.t index c626602..dcd6c1a 100755 --- a/t/easy.t +++ b/t/easy.t @@ -18,7 +18,7 @@ sub ok { (+shift) ? print "ok\n" : print "not ok\n"; } sub nok { (+shift) ? print "not ok\n" : print "ok\n"; } sub msg { return unless $ENV{D}; print STDERR "#" . +shift . "\n"; } -try "plan 90"; +try "plan 98"; try " cat $ENV{HOME}/.gitolite.rc @@ -117,6 +117,11 @@ $ENV{GL_USER} = "u2"; ok(can_write("aa")); $ENV{GL_USER} = "u3"; nok(can_write("aa")); $ENV{GL_USER} = "u4"; nok(can_write("aa")); +$ENV{GL_USER} = "u1"; ok(can_write("aa", "+")); +$ENV{GL_USER} = "u2"; nok(can_write("aa", "+")); +$ENV{GL_USER} = "u3"; nok(can_write("aa", "+")); +$ENV{GL_USER} = "u4"; nok(can_write("aa", "+")); + $ENV{GL_USER} = "u1"; nok(can_write("bb")); $ENV{GL_USER} = "u2"; nok(can_write("bb")); $ENV{GL_USER} = "u3"; nok(can_write("bb")); @@ -132,6 +137,11 @@ $ENV{GL_USER} = "u4"; ok(can_write("cc/u4")); $ENV{GL_USER} = "u5"; ok(can_write("cc/u4")); $ENV{GL_USER} = "u6"; nok(can_write("cc/u4")); +$ENV{GL_USER} = "u3"; nok(can_write("cc/u4", "+")); +$ENV{GL_USER} = "u4"; ok(can_write("cc/u4", "+")); +$ENV{GL_USER} = "u5"; ok(can_write("cc/u4", "+")); +$ENV{GL_USER} = "u6"; nok(can_write("cc/u4", "+")); + # config try("glt ls-remote u4 cc/sub/one; /Initialized empty.*cc/sub/one/"); try("glt ls-remote u4 cc/two; /Initialized empty.*cc/two/");