Gitolite 和存储在一台服务器上的 Web 服务器。目录/var/www/site
是回购“站点”的克隆。Git 用户包含在组 www-data 中。我有/home/git/repositories/site.git/hooks/post-update hook
:
#!/bin/sh
unset GIT_DIR
cd /var/www/site && git pull origin master
一切正常,但在“拉”所有更新或新文件后将所有者更改为 git:git。我不知道如何在没有 root 用户权限的情况下更改所有者。有什么建议么?
我找到了很好的方法(更新后):
#!/bin/sh
PATH=/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
PROJECT="projectname"
GIT_URL="http://factory.domain.ru/git"
git update-server-info
if [ ! -f $1 ]; then
exit 0
fi
while [ -n "$1" ]
do
REF=`echo $1 | awk --field-separator="/" '{print $2}'`
if [ $REF = "branches" -o $REF = "heads" ]; then
BRANCH=`echo $1 | awk --field-separator="/" '{print $3}'`
if [ ! -d /srv/www/$PROJECT/repo/master ]; then
mkdir -p /srv/www/$PROJECT/repo
GIT_SSL_NO_VERIFY=true git clone $GIT_URL/$PROJECT /srv/www/$PROJECT/repo/master
fi
if [ ! -d /srv/www/$PROJECT/repo/$BRANCH ]; then
GIT_SSL_NO_VERIFY=true git clone -b $BRANCH $GIT_URL/$PROJECT /srv/www/$PROJECT/repo/$BRANCH
else
cd /srv/www/$PROJECT/repo/$BRANCH
GIT_SSL_NO_VERIFY=true git fetch origin
GIT_SSL_NO_VERIFY=true git reset --hard origin/$BRANCH
GIT_SSL_NO_VERIFY=true git clean -d -f
GIT_SSL_NO_VERIFY=true git checkout
GIT_SSL_NO_VERIFY=true git pull
fi
fi
shift
done
和“更新”:
#!/bin/sh
refname="$1"
oldrev="$2"
newrev="$3"
PROJECT="projectname"
# --- Safety check
if [ -z "$GIT_DIR" ]; then
echo "Don't run this script from the command line." >&2
echo " (if you want, you could supply GIT_DIR then run" >&2
echo " $0 <ref> <oldrev> <newrev>)" >&2
exit 1
fi
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
exit 1
fi
# --- Check types
# if $newrev is 0000...0000, it's a commit to delete a ref.
zero="0000000000000000000000000000000000000000"
if [ "$newrev" = "$zero" ]; then
newrev_type=delete
else
newrev_type=$(git cat-file -t $newrev)
fi
BRANCH=`echo $1 | awk --field-separator="/" '{print $3}'`
delete () {
mv /srv/www/$PROJECT/repo/$BRANCH /srv/www/$PROJECT/repo/$BRANCH.removed_by_git
rm -rf /srv/www/$PROJECT/repo/$BRANCH.removed_by_git
}
case "$refname","$newrev_type" in
refs/heads/*,delete)
# delete branch
delete
;;
refs/remotes/*,delete)
# delete tracking branch
delete
;;
esac
exit 0