【问题标题】:Using a post-receive hook to create a zip使用接收后挂钩创建 zip
【发布时间】:2012-12-05 14:10:03
【问题描述】:

我已经玩了一段时间的钩子了,但我似乎无法让 post-receive 钩子按我需要的方式工作。

我正在尝试使用post-receive 挂钩来创建一个 zip 文件夹,并在我将更改推送到存储库后将其放置在 git 存储库文件夹之外的某个位置。

【问题讨论】:

  • 你应该在你的问题中包含你写的钩子。

标签: git git-bash git-post-receive


【解决方案1】:

你有一个很好的例子,通过 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,请创建”问题是我不知道如何或在哪里创建'/tmp'
  • @MikeyJ 很奇怪,因为/tmp,正如它自己的名字所表明的,应该在/(如果是服务器的根目录)下。可能是访问权限问题。
  • 很高兴看到我在 SO 上引用的一些代码 :-) @MikeyJ - 你在 Windows 上使用的是 linux 还是 cgywin?大多数发行版都有一个 /tmp 目录...您在什么时候看到错误,在哪里?
  • @managedheap84 是的,我喜欢你在这个钩子中的方法。请注意,MikeJ 最后一次出现在 Stack Overflow 是去年 2 月。您可能无法立即得到问题的答案;)
猜你喜欢
  • 2011-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-25
  • 2015-11-25
  • 1970-01-01
  • 2023-04-03
相关资源
最近更新 更多