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

Tri*_*red 5 git grails groovy

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

Von*_*onC 6

如果你正在推送一个远程仓库,"它似乎只包含一个大的包文件,没有实际的源代码"(正如你在评论中详细说明的那样),这应该意味着" 裸回购 ",这对你来说很有帮助推动工作树和git数据之间没有任何差异的风险.

然后,如" 我可以使用git使远程服务器保持最新吗? "中描述的那样,另一个(非裸)repo和一个post-update hook裸仓库上的一个将获得你想要的位置.


OP TripWired补充说:

好的,我做的是:

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

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

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

我同意第1步和第2步,但是会使用此脚本,就像在这个问题中一样.

检查它是否适用于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
Run Code Online (Sandbox Code Playgroud)


Cas*_*bel 5

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

也就是说,有很多方法可以做你想要做的事情.

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

  • 你可以直接检查来自裸仓库的文件(使用git read-treegit checkout-index)(想到一个例子,git.git的install-doc-quick.sh).

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

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