git checkout bare with submodules in post-receive

怎甘沉沦 提交于 2019-12-07 07:47:59

问题


how may I checkout a bare repository on my server in a post-receive hook that includes submodules?

I currently have this as a post-receive hook:

#!/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

But with this the submodules wont get initialized.

I tried doing this for testing manual:

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 command failed with this error messages:

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

That behavior is already (unanswered) questioned here: Git submodules with separate work_tree

It would also be good if it would not reinitialize them if they are alredy there.


回答1:


--work-tree does not work well with submodules (becoz submodule need another repos, but it can't put in your worktree). You need a separate clone for that.

Just create a clone, do a cd + pull in your hook.



来源:https://stackoverflow.com/questions/11177399/git-checkout-bare-with-submodules-in-post-receive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!