是否可以在不手动编辑 gitolite.conf 文件的情况下修改 wild respos 的 git 配置选项?
Is it possible to modify git config options for wild respos without manually editing the gitolite.conf file?
假设我已经推送并配置了 wild 仓库 foo/bar
。
如果我想向这个 repo 添加邮件列表选项,一种方法是将以下内容添加到我的 gitolite.conf 文件中。
repo foo/ba[r]
config hooks.mailinglist = foo@bar.com
但是,这要求我有权访问 gitolite.conf
,它是 gitolite-admin
存储库的一部分。
普通用户是否可以在不访问管理配置文件的情况下进行此修改?
请注意,我已经仔细阅读了 documentation 无济于事。
我得到了 following answer from the gitolite mailing list。但是,这个答案不处理 GIT_CONFIG_KEYS 中的通配符,所以我修改它以像 gitolite 一样处理这个问题。
只需在 commands/config
中插入以下内容,然后将 config
添加到 .gitolite.rc
中的启用选项列表即可。
#!/bin/bash
# Usage: ssh git@host config <repo> --get <name>
# ssh git@host config <repo> --set <name> <value>
# ssh git@host config <repo> --unset <name>
#
# Set a "git config" option on a repo. You must be an owner of the
# repo, and the config option name must be allowed by the gitolite.rc
# configuration.
die() { echo "$@" >&2; exit 1; }
usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < [=10=]; exit 1; }
[ -z "" ] && usage
[ "" = "-h" ] && usage
[ -z "$GL_USER" ] && die GL_USER not set
repo=""; shift
gitolite owns "$repo" || die "repository '$repo' missing or you do not own it"
cd `gitolite query-rc GL_REPO_BASE`/"$repo".git || die "missing repository ''";
case in
--get) action='--get'
shift
[ "$#" -eq 1 ] || usage
;;
--set) action='--set'
shift
[ "$#" -gt 1 ] || usage
;;
--unset)
action='--unset'
shift
[ "$#" -eq 1 ] || usage
;;
*) if [ "$#" -eq 1 ]
then action='--get'
else action='--set'
fi
;;
esac
name=""; shift
ALLOWED_CONFIG=$(gitolite query-rc GIT_CONFIG_KEYS)
export ALLOWED_CONFIG
export name
deny=$(perl -e '
my @validkeys = split( " ", ( $ENV{ALLOWED_CONFIG} || "" ) );
my @matched = grep { $ENV{name} =~ /^$_$/i } @validkeys;
if (@matched < 1) {print "Denied\n";}')
if [[ -n "$deny" ]]; then
die "config option '$name' not allowed by gitolite.rc"
exit 1
fi
# there is not much need to sanitise the input; by default all
# arguments to commands are restricted to these: -0-9a-zA-Z._\@/+ :,\%=
# (see Gitolite::Rc.pm, the variable is $REMOTE_COMMAND_PATT) however
# for safety we will check the value for consistency with $UNSAFE_PATT
UNSAFE_PATT='.*[`~#$\&()|;<>]'
case $action in
--set) if expr "$*" : "$UNSAFE_PATT" >/dev/null
then
die "value '$*' contains unsafe characters"
else
git config "$name" "$*"
fi
;;
*) git config $action "$name"
;;
esac
假设我已经推送并配置了 wild 仓库 foo/bar
。
如果我想向这个 repo 添加邮件列表选项,一种方法是将以下内容添加到我的 gitolite.conf 文件中。
repo foo/ba[r]
config hooks.mailinglist = foo@bar.com
但是,这要求我有权访问 gitolite.conf
,它是 gitolite-admin
存储库的一部分。
普通用户是否可以在不访问管理配置文件的情况下进行此修改?
请注意,我已经仔细阅读了 documentation 无济于事。
我得到了 following answer from the gitolite mailing list。但是,这个答案不处理 GIT_CONFIG_KEYS 中的通配符,所以我修改它以像 gitolite 一样处理这个问题。
只需在 commands/config
中插入以下内容,然后将 config
添加到 .gitolite.rc
中的启用选项列表即可。
#!/bin/bash
# Usage: ssh git@host config <repo> --get <name>
# ssh git@host config <repo> --set <name> <value>
# ssh git@host config <repo> --unset <name>
#
# Set a "git config" option on a repo. You must be an owner of the
# repo, and the config option name must be allowed by the gitolite.rc
# configuration.
die() { echo "$@" >&2; exit 1; }
usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < [=10=]; exit 1; }
[ -z "" ] && usage
[ "" = "-h" ] && usage
[ -z "$GL_USER" ] && die GL_USER not set
repo=""; shift
gitolite owns "$repo" || die "repository '$repo' missing or you do not own it"
cd `gitolite query-rc GL_REPO_BASE`/"$repo".git || die "missing repository ''";
case in
--get) action='--get'
shift
[ "$#" -eq 1 ] || usage
;;
--set) action='--set'
shift
[ "$#" -gt 1 ] || usage
;;
--unset)
action='--unset'
shift
[ "$#" -eq 1 ] || usage
;;
*) if [ "$#" -eq 1 ]
then action='--get'
else action='--set'
fi
;;
esac
name=""; shift
ALLOWED_CONFIG=$(gitolite query-rc GIT_CONFIG_KEYS)
export ALLOWED_CONFIG
export name
deny=$(perl -e '
my @validkeys = split( " ", ( $ENV{ALLOWED_CONFIG} || "" ) );
my @matched = grep { $ENV{name} =~ /^$_$/i } @validkeys;
if (@matched < 1) {print "Denied\n";}')
if [[ -n "$deny" ]]; then
die "config option '$name' not allowed by gitolite.rc"
exit 1
fi
# there is not much need to sanitise the input; by default all
# arguments to commands are restricted to these: -0-9a-zA-Z._\@/+ :,\%=
# (see Gitolite::Rc.pm, the variable is $REMOTE_COMMAND_PATT) however
# for safety we will check the value for consistency with $UNSAFE_PATT
UNSAFE_PATT='.*[`~#$\&()|;<>]'
case $action in
--set) if expr "$*" : "$UNSAFE_PATT" >/dev/null
then
die "value '$*' contains unsafe characters"
else
git config "$name" "$*"
fi
;;
*) git config $action "$name"
;;
esac