git checkout裸露在接收后的子模块中

时间:2012-06-24 12:23:02

标签: git git-submodules git-post-receive

如何在包含子模块的post-receive钩子中检查我的服务器上的裸存储库?

我目前将此作为收件后挂钩:

#!/bin/bash

# http://blog.ekynoxe.com/2011/10/22/git-post-receive-for-multiple-remote-branches-and-work-trees/
# post-receive hook that checks out development branch after a push to the bare
# repo

# paths must exist
livepath="/var/www/live"
devpath="/var/www/dev"

while read oldrev newrev ref
do
    branch=`echo $ref | cut -d/ -f3`

    #if [[ "master" == "$branch" ]]; then
    #   git --work-tree=$livepath checkout -f $branch
    #   echo 'Changes pushed live.'
    #fi
    if [[ "develop" == "$branch" ]]; then
        git --work-tree=$devpath checkout -f $branch
        echo 'Changes pushed to dev.'
    fi
done

但是这个子模块不会被初始化。

我试过这个测试手册:

cd /var/www/dev
git --work-tree /var/www/dev --git/dir /git/myrepo.git submodule init
git --work-tree /var/www/dev --git/dir /git/myrepo.git submodule update

submodule update命令失败并显示以下错误消息:

fatal: working tree '/var/www/dev' already exists.
Clone of 'https://github.com/yiisoft/yii.git' into submodule path 'yii' failed

这种行为已经(未答复)在这里受到质疑:Git submodules with separate work_tree

如果它们在那里没有重新初始化它们也会很好。

1 个答案:

答案 0 :(得分:0)

--work-tree与子模块不兼容(becoz子模块需要另一个存储库,但它不能放在你的工作树中)。你需要一个单独的克隆。

只需创建一个克隆,在你的钩子中执行cd + pull