Git的挂钩更新基于各分公司Web文件夹推到远程服务器 [英] Git hook to update various web folders based on branch pushed to remote server

查看:186
本文介绍了Git的挂钩更新基于各分公司Web文件夹推到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用的gitosis(Debian Lenny的),我希望能够推到不同的远程回购/位置从而使一个流血的边缘,发布候选,&放一个Web应用程序; 生产版本镜像物理网络目录和codeBase类的应用程序。我想preFER每个目录有应用的一个分支。因此一个资料库,三个活的版本。

I am developing a web application using Gitosis (Debian Lenny) that I want to be able to push to different remote repos/locations thus allowing a "bleeding-edge", "release-candidate", & "production" version of the application with mirrored physical web directories and codebase. I would prefer each directory to have a branch of the application. So one repository, three "live" versions.

我是新到Git所以有可能是一个更好的解决方案,但我所想出瓦特/到目前为止,要么寻找一种方法来连接钩枝(我还没有发现),或者写一个钩子,将过滤器哪个分支正在实施。

I am new to Git so there's probably a better solution but what i've come up w/ so far is either finding a way to attach hooks to branches (which I haven't found) or to write a hook that will filter for which branch is being committed.

我的问题是关于如何建立一个post-update挂钩,将检查的承诺分公司,设置基于分支目录中的变量,硬是codeBase的复制到该目录中它可以瞬间访问通过HTTP?

My question is on how to set up a post-update hook that will check the committed branch, set a variable for the directory based on that branch, and literally copy the codebase into that directory where it can be instantly accessible over HTTP?

git rev-list --branches --pretty=oneline --max-count=1

将返回类似:

cc5112ba59bc82f2e847ac264317c062ce80f69f test commit

但我需要分支本身喜欢试验品或主人的名称。

but i need the name of the branch itself like "experimental" or "master".

所以基本上我在寻找类似:

So basically I'm looking for something like:

1)获取刚犯(例如,master分支的名字,实验)转换成字符串

1) Get name of branch that was just committed (e.g. "master", "experimental") into a string

2)使用bash情况申报使用什么目录

2) Use Bash case to declare what directory to use

3)运行类似。​​混帐归档--format =焦油HEAD |(CD $位置和放大器;&安培;焦油XF - ),其中位置在什么情况下,从返回

3) Run something like "git archive --format=tar HEAD | (cd $LOCATION && tar xf -)" where location is what was returned from case.

我想我是越来越密切与以下但意识到它未返回分支名称,但提交信息,而不是:

I thought I was getting close with the following but realized it didn't return the branch name but the commit message instead:

#!/bin/sh

# Get substr from "sha1[space]commit-msg"
BRANCH=$(git rev-list --pretty=oneline --branches --max-count=1 | awk '{split($0,array," ")} END{print array[2]}')
case $BRANCH in
    "experimental")
        dir="/home/APP_NAME/experimental"
    ;;
    "master")
        dir="/home/APP_NAME/production"
    ;;
esac
# move to location and copy files
git archive --format=tar HEAD | (cd $loc && tar xf -)

我也认识到,如果我总是把分公司作为第一部分的承诺,我可以做到这样的事情,但我真的不想为此担心。

I did realize that if I always put the branch as the first part of the commit I could accomplish something like this but I really don't want to worry about it.

任何帮助将是AP preciated。在此先感谢!

Any help would be appreciated. Thanks in advance!

推荐答案

也许我失去了一些东西,但如果这是在更新后勾那么你得到正在更新作为参数在钩裁判的名称。例如如果我的推送更新实验在信息库,则更新后调用时需要:

Perhaps I'm missing something, but if this is in a post-update hook then you get the names of the refs that are being updated as parameters to the hook. e.g. if my push updates master and experimental in a repository, then post-update is invoked with:

 post-update refs/heads/master refs/heads/experimental

...你可以用 $ 1 访问它们为 $ 2 往常一样在你的钩子。

... and you can access them with $1 as $2 usual in your hook script.

顺便说一下, githooks 文档指出,你可能要考虑使用后接受勾来代替,该替代得到标准输入的信息 - 然而,它也给你裁判的新旧值以及裁判的名字,这可能是有用的。

Incidentally, the githooks documentation points out that you might want to consider using the post-receive hook instead, which instead gets information on standard input - however, it also gives you the old and new values of the ref as well as the ref name, which might be useful.

这篇关于Git的挂钩更新基于各分公司Web文件夹推到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆