Last active
December 17, 2015 09:49
-
-
Save vStone/5590564 to your computer and use it in GitHub Desktop.
Additional gitolite command to show or set gitweb.* configuration for user-created ("wild") repo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Installation: | |
# To use this script, place it in the commands directory of your | |
# gitolite installation. (Hint: ~/gitolite/src/commands/) | |
# You will also have to add the command to the allowed commands in | |
# your .gitolite.rc configuration file. | |
# | |
# Permissions: | |
# The script requires the same permissions as the desc command. | |
# | |
# Configuration: | |
# You can set WEB_HANDLE_DESC with one of the following values: | |
# 0: Don't touch the description file. | |
# Note that in gitweb, the description file is consulted first. | |
# 1: Remove the description file if one exists. | |
# 2: Update the description file with the same content. | |
# This is one way, the desc command does not integrate with web. | |
# | |
# Example: | |
# WEB_HANDLE_DESC => 1, | |
# Usage: ssh git@host gitweb <repo> -l | |
# ssh git@host gitweb <repo> <key> | |
# ssh git@host gitweb <repo> <key> <description string> | |
# ssh git@host gitweb <repo> <key> -d | |
# | |
# <key> can be 'desc', 'owner' or 'category' | |
# | |
# This command can be used to mange gitweb related configuration in | |
# your repository. You can NOT manage permissions to gitweb with it. | |
die() { echo "$@" >&2; exit 1; } | |
usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; } | |
[ -z "$1" ] && usage | |
[ "$1" = "-h" ] && usage | |
[ -z "$GL_USER" ] && die GL_USER not set | |
# ---------------------------------------------------------------------- | |
repo=${1%.git}; shift | |
# this shell script takes arguments that are completely under the user's | |
# control, so make sure you quote those suckers! | |
# kernel.org needs 'desc' to be available to people who have "RW" or above, | |
# not just the "creator". In fact they need it for non-wild repos so there | |
# *is* no creator. | |
if gitolite query-rc -q WRITER_CAN_UPDATE_DESC | |
then | |
gitolite access -q "$repo" $GL_USER W any || die You are not authorised | |
else | |
gitolite creator "$repo" $GL_USER || die You are not authorised | |
fi | |
update_desc=`gitolite query-rc WEB_HANDLE_DESC || echo '0'` | |
# if it passes, $repo is a valid repo name so it is known to contain only sane | |
# characters. This is because 'gitolite creator' return true only if there | |
# *is* a repo of that name and it has a gl-creator file that contains the same | |
# text as $GL_USER. | |
repo_path=`gitolite query-rc GL_REPO_BASE`/"$repo".git/ | |
gitweb_config() { | |
local key="$1"; | |
shift; | |
local text="$*"; | |
case "$text" in | |
("") git --git-dir "$repo_path" config --local --get gitweb."$key" | |
return $? | |
;; | |
(-d) echo "Removing $key"; | |
git --git-dir "$repo_path" config --local --unset gitweb."$key" | |
return $? | |
;; | |
(*) echo "Setting $key"; | |
git --git-dir "$repo_path" config --local gitweb."$key" "$text" | |
return $? | |
;; | |
esac | |
} | |
case $1 in | |
(-l) git --git-dir "$repo_path" config --local --get-regexp ^gitweb\\. | \ | |
sed 's@^\([^ ]\+\)@\1 =|@' | column -t -s'|'; | |
exit 0;; | |
(desc|description) shift; | |
case "$update_desc" in | |
1) [ -w "$repo_path/description" ] && rm "$repo_path/description";; | |
2) echo "$*" > "$repo_path/description";; | |
*) ;; | |
esac | |
gitweb_config description "$*"; | |
exit $?; | |
;; | |
(owner) shift; gitweb_config owner "$*"; exit $?;; | |
(category) shift; gitweb_config category "$*"; exit $?;; | |
("") usage; exit 1;; | |
(*) echo "You can only set desc(ription), owner or category"; exit 1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is really great - thanks for sharing