目标是维护2个不严格镜像的独立存储库。这两个存储库都会受到不同开发人员的更新,因此svnsynch是不可能的。
挂钩脚本可能不是正确的解决方案,因为我更喜欢随意运行脚本而不是每次提交。也许是一个比较时间戳并复制最年轻的脚本?请不要建议我们改为git。
答案 0 :(得分:1)
我正在链接到一个hook script,我用它来检查每次提交时存储库的一部分。您可以修改它以满足您的需求;我想你想要将svn checkout
更改为svn export
。
对于后代,我将在这里复制脚本的文本:
#!/bin/bash
# POST-COMMIT HOOK
#
# This is an SVN post-commit hook to automatically update a directory with the contents
# of some part of the SVN repository every time that part of the repository is changed.
fail() {
echo "$@" 1>&2
exit 1
}
# USER and PASS are the username and password of an SVN user with read access to the
# relevant part of the repository
USER=""
PASS=""
# The root of the SVN repository
SVNROOT=""
# The path within the SVN repository to export whenever it's committed
SVNPATH=""
# The directory to hold the checked-out copy
WORKING=""
# Since environment variables are unset
export PATH="/bin:/usr/bin:/usr/local/bin"
getopt=$(which getopt)
TEMP=`$getopt -o u:p:U:P:d: --long user:,pass:,password:,svn-root:,svn-path:,working-dir: -n $0 -- "$@"`
if [ $? != 0 ]; then
fail "Terminating...getopt failed"
fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true; do
case "$1" in
-u|--user)
USER=$2
shift 2;;
-p|--pass|--password)
PASS=$2
shift 2;;
-U|--svn-root)
SVNROOT=$2
shift 2;;
-P|--svn-path)
SVNPATH=$2
shift 2;;
-d|--working-dir)
WORKING=$2
shift 2;;
--)
shift
break ;;
*)
fail "Option error!";;
esac
done
test -n $SVNROOT || fail "Missing option --svn-root"
test -n $SVNPATH || fail "Missing option --svn-path"
test -n $WORKING || fail "Missing option --working-dir"
REPOS="$1"
REV="$2"
# The path to SVN executables
svnbin=$(which svn)
svnlook=$(which svnlook)
# The path to grep
grep=$(which egrep)
if test -n "$USER"; then
AUTHSTR="--username $USER --password $PASS"
else
AUTHSTR=""
fi
svnexport="$svnbin export --revision $REV $AUTHSTR"
svnupdate="$svnbin update --revision $REV $AUTHSTR"
svncheckout="$svnbin checkout --revision $REV $AUTHSTR"
svnchanged="$svnlook changed $REPOS --revision $REV"
grepq="$grep -q"
# If anything in the desired path has been changed
if $svnchanged | $grepq "^[A-Z]+[[:space:]]+$SVNPATH"; then
# Check it out to the web root
if test -d $WORKING/.svn; then
$svnupdate $WORKING || fail "svnupdate failed"
else
$svncheckout file://$SVNROOT/$SVNPATH $WORKING || fail "svncheckout failed"
fi
fi