#!/bin/sh # Gitolite permission manipulation helper script # Copyright 2011, Michal Sojka # License: GNU GPLv2+ curr_branch=$(git symbolic-ref -q HEAD) curr_branch_short="${curr_branch#refs/heads/}" remote=$(git config --get branch.$curr_branch_short.remote) url=$(git config --get remote.$remote.url) || url=$remote url_sans_ssh=${url#ssh://} if test x$url_sans_ssh != x$url; then userhost=${url_sans_ssh%%/*} repo=${url_sans_ssh#*/} else # scp-like syntax userhost=${url%%:*} repo=${url#*:} fi bn=$(basename $0) if test x$bn = xgl-perm; then cmd=$1; shift else cmd=$bn fi case $cmd in gl-getperms|get) if test $# -gt 0; then echo >&2 "Command $cmd does not accept any arguments"; exit 1; fi ssh $userhost getperms $repo;; gl-setperms|set) if test $# -gt 0; then echo >&2 "Command $cmd does not accept any arguments - it reads from stdin"; exit 1; fi ssh $userhost setperms $repo;; gl-addperm|add) perms=$(ssh $userhost getperms $repo) ( test "$perms" && echo "$perms"; echo $* ) | ssh $userhost setperms $repo;; gl-rmperm|rm) user=$1 perms=$(ssh $userhost getperms $repo) # setperms does not work when executed in the same pipe with getperms echo "$perms" | sed -e "s/[[:space:]]*\\b$user\\b//g" -e "/^[[:alnum:]]\+[[:space:]]*$/d" | ssh $userhost setperms $repo;; esac