2015-02-24 49 views
2

假設我推送並配置了野生回購foo/bar是否可以在不手動編輯gitolite.conf文件的情況下修改野生respos的git config選項?

如果我想爲此回購添加郵件列表選項,一種方法是將以下內容添加到我的gitolite.conf文件中。

repo foo/ba[r] 
    config hooks.mailinglist = [email protected] 

然而,這需要我有機會獲得gitolite.conf這是gitolite-admin庫的一部分。

有什麼方法可以讓普通用戶進行此修改,而無需訪問管理配置文件?

請注意,我已經閱讀documentation無濟於事。

回答

2

我從gitolite mailing list得到following answer。然而,這個答案不能處理GIT_CONFIG_KEYS中的通配符,所以我修改它以與gitolite一樣處理。

它在commands/config中插入以下內容,然後將config添加到.gitolite.rc的已啓用選項列表中。

#!/bin/bash 

# Usage: ssh [email protected] config <repo> --get <name> 
#   ssh [email protected] config <repo> --set <name> <value> 
#   ssh [email protected] 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 "[email protected]" >&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"; 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 '$1'"; 

case $1 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="$1"; 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 
相關問題