如何使用git签入文件进行构建?

时间:2010-01-29 18:02:44

标签: git grails groovy

我正在使用git来管理我的grails项目。我在远程服务器上设置了一个git存储库,我想要做的就是当我在本地运行代码时,我想提交它并推送到远程服务器。我希望将更新的groovy文件和gsp放在远程服务器上的正确位置,以便grails将获取远程测试的更改。这可能吗?

3 个答案:

答案 0 :(得分:6)

如果您要推送到远程仓库,“它似乎只包含一个大包文件,没有实际的源代码”(正如您在评论中详细说明的那样),那应该是“bare repo”,其中它是有益的,它允许你推动工作树和git数据之间没有任何差异的风险。

然后,如“Can I use git to keep a remote server up to date?”中所述,裸回购方的另一个(非裸)回购和post-update hook将为您提供所需的位置。


OP TripWired添加:

  

好的,我做的是:

  • 创建用于签入的裸仓库
  • 我创建了另一个标准的回购,基本上我有~/project.git~/project
  • 我将project.git克隆到projectproject.git/hooks/post-update我放了:

    cd ../../project env -i git checkout。 env -i git pull

  

我还确保更新后的内容是可执行的   当我从命令行运行钩子时它工作正常,但是当我检查回购时它似乎不起作用。

我同意步骤1和2,但会使用this script,就像在this question中一样。

检查它是否适用于您当地仓库中的git push到您的裸仓库。

#!/bin/sh
#
# This hook does two things:
#
#  1. update the "info" files that allow the list of references to be
#     queries over dumb transports such as http
#
#  2. if this repository looks like it is a non-bare repository, and
#     the checked-out branch is pushed to, then update the working copy.
#     This makes "push" function somewhat similarly to darcs and bzr.
#
# To enable this hook, make this file executable by "chmod +x post-update".

git-update-server-info

is_bare=$(git-config --get --bool core.bare)

if [ -z "$is_bare" ]
then
    # for compatibility's sake, guess
    git_dir_full=$(cd $GIT_DIR; pwd)
    case $git_dir_full in */.git) is_bare=false;; *) is_bare=true;; esac
fi

update_wc() {
    ref=$1
    echo "Push to checked out branch $ref" >&2
    if [ ! -f $GIT_DIR/logs/HEAD ]
    then
        echo "E:push to non-bare repository requires a HEAD reflog" >&2
        exit 1
    fi
    if (cd $GIT_WORK_TREE; git-diff-files -q --exit-code >/dev/null)
    then
        wc_dirty=0
    else
        echo "W:unstaged changes found in working copy" >&2
        wc_dirty=1
        desc="working copy"
    fi
    if git diff-index --cached HEAD@{1} >/dev/null
    then
        index_dirty=0
    else
        echo "W:uncommitted, staged changes found" >&2
        index_dirty=1
        if [ -n "$desc" ]
        then
            desc="$desc and index"
        else
            desc="index"
        fi
    fi
    if [ "$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]
    then
        new=$(git rev-parse HEAD)
        echo "W:stashing dirty $desc - see git-stash(1)" >&2
        ( trap 'echo trapped $$; git symbolic-ref HEAD "'"$ref"'"' 2 3 13 15 ERR EXIT
        git-update-ref --no-deref HEAD HEAD@{1}
        cd $GIT_WORK_TREE
        git stash save "dirty $desc before update to $new";
        git-symbolic-ref HEAD "$ref"
        )
    fi

    # eye candy - show the WC updates :)
    echo "Updating working copy" >&2
    (cd $GIT_WORK_TREE
    git-diff-index -R --name-status HEAD >&2
    git-reset --hard HEAD)
}

if [ "$is_bare" = "false" ]
then
    active_branch=`git-symbolic-ref HEAD`
    export GIT_DIR=$(cd $GIT_DIR; pwd)
    GIT_WORK_TREE=${GIT_WORK_TREE-..}
    for ref
    do
        if [ "$ref" = "$active_branch" ]
        then
            update_wc $ref
        fi
    done
fi

答案 1 :(得分:5)

关于你对Alos帖子的评论:远程是所谓的裸存储库 - 它包含整个存储库,除了内容的签出副本。我们的想法是,对于您只是推送和拉出的中央存储库,不需要拥有这些文件。

尽管如此,有很多方法可以做你想做的事情。

  • 您可以创建另一个远程非裸克隆,并使用它从裸露的克隆中进行拉取并进行测试。这可能是最简单的。

  • 您可以直接从裸仓库中检出文件(使用git read-treegit checkout-index)(想到一个例子,git.git的install-doc-quick.sh)。

  • 您甚至可以使用非裸机,但请记住,由于工作树无法更新,因此推入非裸机库是危险的。根据您的git版本,您必须覆盖各种安全措施,并且在推送后可以修复工作树(可能是git reset --hard)。

无论采用哪种方法,假设您希望在每次推送后触发测试,都可以使用post-receive or post-update hook来执行此操作。 (你可以检查自上次测试以来的时间长度,如果你想避免一次推动反复测试)

答案 2 :(得分:0)

如果您使用的是Linux,则可以设置一个cron作业来为您复制文件,或者如果您使用的是Windows,则可以创建一个带有小bat或vbs脚本的计划任务,以将文件复制到远程服务器。如果您需要有关使用Git的帮助,请参阅用户手册。如果那不是你想要的东西,我们就可以开展一些可能更好的工作,或者如果你需要有关脚本的帮助,请告诉我。