From 5b3dcb375774c4056e1c656030ab9eb9042733ee Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Wed, 27 Oct 2010 23:08:58 +0530 Subject: [PATCH] a slew of adc changes; details below: - get_rights_and_owner normalises its arg1 by stripping .git if supplied, then sets the variable "repo" to the result as a side effect - new "help" adc with some default text but main purpose is to allow site local help text - other adc's refer to 'help' adc when appropriate - 'undelete' renamed to 'restore'; that's what the KDE "trashcan" program calls that operation - minor typo in sample script in documentation - main adc doc points to contrib/adc/repo-deletion.README now --- contrib/adc/adc.common-functions | 7 ++--- contrib/adc/fork | 8 +++--- contrib/adc/help | 44 +++++++++++++++++++++++++++++++ contrib/adc/lock | 2 +- contrib/adc/repo-deletion.README | 4 +-- contrib/adc/{undelete => restore} | 0 contrib/adc/rm | 2 +- contrib/adc/rmrepo | 2 +- contrib/adc/trash | 4 +-- contrib/adc/unlock | 2 +- contrib/adc/who-pushed | 4 +-- doc/admin-defined-commands.mkd | 14 ++++------ 12 files changed, 66 insertions(+), 27 deletions(-) create mode 100755 contrib/adc/help rename contrib/adc/{undelete => restore} (100%) diff --git a/contrib/adc/adc.common-functions b/contrib/adc/adc.common-functions index 3b0bfc1..996e641 100644 --- a/contrib/adc/adc.common-functions +++ b/contrib/adc/adc.common-functions @@ -26,9 +26,8 @@ opt() { valid_owned_repo() { # check that an arg passed is a valid repo and the current user owns it - repo=$1 [ -z "$1" ] && die need a repo name - get_rights_and_owner $repo + get_rights_and_owner $1 [ "$owner" = "$GL_USER" ] || die "$repo does not exist or is not yours!" # and we sneak this in too, quietly :) @@ -37,9 +36,11 @@ valid_owned_repo() { die() { echo "$@"; exit 1; } +# NOTE: this also sets $repo to the normalised (without .git suffix) reponame get_rights_and_owner() { local ans - ans=$(perl -I$GL_BINDIR -Mgitolite -e 'cli_repo_rights("'$1'")') + repo=${1%.git} + ans=$(perl -I$GL_BINDIR -Mgitolite -e 'cli_repo_rights("'$repo'")') # set shell variables as needed owner=${ans#* } diff --git a/contrib/adc/fork b/contrib/adc/fork index 224be36..22d451f 100755 --- a/contrib/adc/fork +++ b/contrib/adc/fork @@ -1,14 +1,12 @@ #!/bin/sh -from=$1 -to=$2 - . $(dirname $0)/adc.common-functions -get_rights_and_owner $from +# get_rights_and_owner now also sets $repo; see comments in common functions +get_rights_and_owner $1; from=$repo [ -z "$perm_read" ] && die "no read permissions on $from" -get_rights_and_owner $to +get_rights_and_owner $2; to=$repo [ -z "$perm_create" ] && die "no create permissions on $to" # clone $from to $to diff --git a/contrib/adc/help b/contrib/adc/help new file mode 100755 index 0000000..b53a03e --- /dev/null +++ b/contrib/adc/help @@ -0,0 +1,44 @@ +#!/bin/sh + +. $(dirname $0)/adc.common-functions + +# the local site can have a file called gl-adc-help.txt, which will be used as +# the *entire* help text for this site... + +[ -f $HOME/gl-adc-help.txt ] && { + cat $HOME/gl-adc-help.txt + exit 0 +} + +# or the local site will use the default help text in this file, with an +# optional pre- and post- text that is site local (like maybe the admin's +# contact details) + +# pre +[ -f $HOME/gl-adc-pre-help.txt ] && cat $HOME/gl-adc-pre-help.txt + +# default help text +cat </dev/null || die "failed creating directory in trashcan" [ -d $TRASH_CAN/$repo/$TRASH_SUFFIX ] && die try again in a few seconds mv $repo.git $TRASH_CAN/$repo/$TRASH_SUFFIX -echo $repo moved to trashcan +echo "$repo moved to trashcan. Please run the 'help' adc for more info." diff --git a/contrib/adc/unlock b/contrib/adc/unlock index 77536ad..c9df683 100755 --- a/contrib/adc/unlock +++ b/contrib/adc/unlock @@ -9,4 +9,4 @@ valid_owned_repo $1 touch $repo.git/gl-rm-ok -echo "$repo has been unlocked and can be 'rm'ed or 'lock'ed once again" +echo "$repo has been unlocked. Please run the 'help' command for more info." diff --git a/contrib/adc/who-pushed b/contrib/adc/who-pushed index 9d90807..f1eec21 100755 --- a/contrib/adc/who-pushed +++ b/contrib/adc/who-pushed @@ -7,11 +7,11 @@ . $(dirname $0)/adc.common-functions -repo=$1 sha=$2 [ -n "$sha" ] || die Usage: ssh ... who-pushed reponame SHA \# at least first few hex digits -get_rights_and_owner $repo +# get_rights_and_owner now also sets $repo; see comments in common functions +get_rights_and_owner $1 [ -z "$perm_read" ] && die "no read permissions on $repo" cd $GL_REPO_BASE_ABS/$repo.git diff --git a/doc/admin-defined-commands.mkd b/doc/admin-defined-commands.mkd index eb0fa97..1ee04ce 100644 --- a/doc/admin-defined-commands.mkd +++ b/doc/admin-defined-commands.mkd @@ -16,7 +16,7 @@ In this document: * anatomy of a command * example uses and sample commands in contrib * fork - * rmrepo + * deleting/trashing repos * enable/disable push access temporarily * (bonus) restricted admin @@ -164,17 +164,13 @@ or some such incantation. - + -#### rmrepo +#### deleting/trashing repos -This is one thing that you really could not do before this setup was created. -Use it like this: +See [contrib/adc/repo-deletion.README][rdR] for details about this. - ssh git@server rmrepo reponame - -The script checks to make sure that the repo being deleted was *created* by -the user invoking it. +[rdR]: http://github.com/sitaramc/gitolite/blob/pu/contrib/adc/repo-deletion.README