【问题标题】:git checkout bare with submodules in post-receivegit checkout 裸露在 post-receive 中的子模块
【发布时间】:2012-06-24 12:23:01
【问题描述】:

如何在包含子模块的接收后挂钩中签出服务器上的裸存储库?

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

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

如果它们已经在那里,它不会重新初始化它们也很好。

【问题讨论】:

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


    【解决方案1】:

    --work-tree 不适用于子模块(因为子模块需要另一个存储库,但它不能放入您的工作树中)。为此,您需要一个单独的克隆。

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

    【讨论】:

    • 我认为你是对的,如果一个 git 项目包含子模块,它不适用于当前版本的 git。我只是按照您的建议进行了操作并创建了一个克隆,取消设置 git 变量并从该存储库中执行了 git pull。我仍然认为我以前尝试的方式应该是可能的。
    猜你喜欢
    • 2017-09-21
    • 1970-01-01
    • 2015-03-29
    • 2012-02-17
    • 2014-05-13
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    相关资源
    最近更新 更多