【发布时间】:2012-12-05 14:10:03
【问题描述】:
我已经玩了一段时间的钩子了,但我似乎无法让 post-receive 钩子按我需要的方式工作。
我正在尝试使用post-receive 挂钩来创建一个 zip 文件夹,并在我将更改推送到存储库后将其放置在 git 存储库文件夹之外的某个位置。
【问题讨论】:
-
你应该在你的问题中包含你写的钩子。
标签: git git-bash git-post-receive
我已经玩了一段时间的钩子了,但我似乎无法让 post-receive 钩子按我需要的方式工作。
我正在尝试使用post-receive 挂钩来创建一个 zip 文件夹,并在我将更改推送到存储库后将其放置在 git 存储库文件夹之外的某个位置。
【问题讨论】:
标签: git git-bash git-post-receive
你有一个很好的例子,通过 this article 中的 post-receive 钩子从 Daniel Byrne 部署 zip:
想法是使用git archive --format=zip:
#!/bin/bash
#
# A post commit hook that takes any updates pushed to the 'release' branch
# and creates a release directory for the new version under the webroot.
# Live site is then symlinked to this new release directory.
oldrev=$1
newrev=$2
branch=$3
# this is the root of the website (a symlink to a release directory)
webroot=/var/www/danielbyrne.net/www
if [ "$branch" == "release" ]
then
# create a release directory to extract files into
target=/var/www/danielbyrne.net/releases/$2/
mkdir $target
echo "Making target directory: $target"
# create an archive in the webroot of danielbyrne.net
/usr/bin/git archive master --format zip --output $target/deploy.zip
echo "unzipping archive..."
# extract the archive
unzip -o -q $target/deploy.zip -d $target
echo "removing deployment archive"
# remove the archive file
rm $target/deploy.zip
echo "switching symbolic link to $target"
# now switch the live site to point to the new release
ln -nsf $target $webroot
echo "done";
fi
【讨论】:
/tmp,正如它自己的名字所表明的,应该在/(如果是服务器的根目录)下。可能是访问权限问题。