diff options
author | Sitaram Chamarty <sitaram@atc.tcs.com> | 2014-06-08 09:48:09 +0530 |
---|---|---|
committer | Sitaram Chamarty <sitaram@atc.tcs.com> | 2014-06-08 18:25:04 +0530 |
commit | 07ce4b90342d25fdeea5b987cce2342aaa180f25 (patch) | |
tree | 4986528e2539232927b96d2724d09f6553d5092b | |
parent | allow commands to be defined in non-core list (diff) | |
download | gitolite-gentoo-07ce4b90342d25fdeea5b987cce2342aaa180f25.tar.gz gitolite-gentoo-07ce4b90342d25fdeea5b987cce2342aaa180f25.tar.bz2 gitolite-gentoo-07ce4b90342d25fdeea5b987cce2342aaa180f25.zip |
new motd command; see command help for details
-rwxr-xr-x | src/commands/motd | 53 | ||||
-rw-r--r-- | src/lib/Gitolite/Rc.pm | 7 | ||||
-rw-r--r-- | src/lib/Gitolite/Triggers/Motd.pm | 29 |
3 files changed, 89 insertions, 0 deletions
diff --git a/src/commands/motd b/src/commands/motd new file mode 100755 index 0000000..b56e99e --- /dev/null +++ b/src/commands/motd @@ -0,0 +1,53 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use lib $ENV{GL_LIBDIR}; +use Gitolite::Easy; + +=for usage +Usage: ssh git@host motd <repo> rm + cat <filename> | ssh git@host motd <repo> set + +Remove or set the motd file for repo or the whole system. + +For a repo: you need to have write access to the repo and the +'writer-is-owner' option must be set for the repo, or it must be a +user-created ('wild') repo and you must be the owner. + +For the whole system: you need to be an admin (have write access to the +gitolite-admin repo). Use @all in place of the repo name. + +PLEASE NOTE that if you're using http mode, the motd will only appear for +gitolite commands, not for normal git operations. This in turn means that +only the system wide motd can be seen; repo level motd's never show up. +=cut + +usage() if not @ARGV or @ARGV < 1 or $ARGV[0] eq '-h'; + +my $repo = shift; +my $op = shift || ''; +usage() if $op ne 'rm' and $op ne 'set'; +my $file = "gl-motd"; + +#<<< +_die "you are not authorized" unless + ( $repo eq '@all' and is_admin() ) or + ( $repo ne '@all' and owns($repo) ) or + ( $repo ne '@all' and can_write($repo) and option( $repo, 'writer-is-owner' ) ); +#>>> + +my @out = + $repo eq '@all' + ? ( dir => $rc{GL_ADMIN_BASE} ) + : ( repo => $repo ); + +if ( $op eq 'rm' ) { + $repo eq '@all' + ? unlink "$rc{GL_ADMIN_BASE}/$file" + : unlink "$rc{GL_REPO_BASE}/$repo.git/$file"; +} elsif ( $op eq 'set' ) { + textfile( file => $file, @out, prompt => '' ); +} else { + print textfile( file => $file, @out, ); +} diff --git a/src/lib/Gitolite/Rc.pm b/src/lib/Gitolite/Rc.pm index 91aa36f..5651b06 100644 --- a/src/lib/Gitolite/Rc.pm +++ b/src/lib/Gitolite/Rc.pm @@ -420,6 +420,10 @@ BEGIN { Alias INPUT :: + Motd INPUT :: + Motd PRE_GIT :: + Motd COMMAND motd + Mirroring INPUT :: Mirroring PRE_GIT :: Mirroring POST_GIT :: @@ -598,6 +602,9 @@ __DATA__ # show more detailed messages on deny # 'expand-deny-messages', + # show a message of the day + # 'Motd', + # system admin stuff # enable mirroring (don't forget to set the HOSTNAME too!) diff --git a/src/lib/Gitolite/Triggers/Motd.pm b/src/lib/Gitolite/Triggers/Motd.pm new file mode 100644 index 0000000..6de80a2 --- /dev/null +++ b/src/lib/Gitolite/Triggers/Motd.pm @@ -0,0 +1,29 @@ +package Gitolite::Triggers::Motd; + +use Gitolite::Rc; +use Gitolite::Common; + +use strict; +use warnings; + +# print a message of the day to STDERR +# ---------------------------------------------------------------------- + +my $file = "gl-motd"; + +sub input { + # at present, we print it for every single interaction with gitolite. We + # may want to change that later; if we do, get code from Kindergarten.pm + # to get the gitcmd+repo or cmd+args so you can filter on them + + my $f = "$rc{GL_ADMIN_BASE}/$file"; + print STDERR slurp($f) if -f $f; +} + +sub pre_git { + my $repo = $_[1]; + my $f = "$rc{GL_REPO_BASE}/$repo.git/$file"; + print STDERR slurp($f) if -f $f; +} + +1; |