gitolite后接收特定裸露回购钩 [英] gitolite post receive hook for specific bare repo

查看:79
本文介绍了gitolite后接收特定裸露回购钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将本地git仓库推送到服务器后:

  $ git push origin master 

我希望服务器上的裸回购(在收到我的推送信息后)到:

  $ cd / Users / me / Sites 
$ git pull
$ exit

我在这里看过一些问题,他们提到了$ HOME / gitolite / hooks中的钩子,

但这里是我的工作:

  git @ mm:gitolite $ pwd 
/ Users / git / gitolite
git @ mm:gitolite $ ls
.git / README.txt install *
CHANGELOG check-g2-compat * src /
COPYING convert-gitosis-conf * t /

如何为特定裸露回购添加后接收挂钩?



如果我进入我的裸回购:

  git @ mm:bare-repo.git $ ls钩子
applypatch-msg.sample * pre-rebase.sample *
commit-msg.sample * prepare-commit-msg.sample *
post-update.sample * update @
pre-applypatch.sample * update.sample *
pre-commit.sample *
code>

我没有看到post-receive钩子。什么给了?

解决方案

2013年8月更新了最新gitolite:
您现在拥有


基本上只是创建一个指向 $ rc {LOCAL_CODE} / hooks / repo-specific < repo.git> / hooks c>(除了 gitolite-admin 回购)





首先,如果你使用的是gitolite V3,你可以定义任何钩子,包括一个 post-接收钩子(除 update 钩子外,请参阅
使用钩子 ):之前, gitolite V2 pre-receive 钩子被保留。



现在你可以在 gitolite-admin / common / hooks 本地克隆目录中拷贝它,然后按 gitolite-admin 返回到gitolite服务器:gitolite将确保所有所有裸露回购的管理声明为钩。



您也可以添加直接在服务器上的钩子在由 $ LOCAL_CODE rc 变量( rc 表示在您的 gitolite.rc 配置文件): $ LOCAL_CODE / hooks / common 。请参阅自定义gitolite

这个想法是确保gitolite升级不会擦除您的任何自定义程序。


只需定义一个'post-receive'文件,可执行文件( chmod 755 ),并将其复制到 common / hooks 您选择的目录( gitolite-admin 本地回购加 git push .gitolite ,或服务器上的 $ LOCAL_CODE )。

注意:您看不到' post-receive.sample '文件并不妨碍您定义该钩子。

如果直接在服务器上完成,则需要运行 gitolite setup --hooks-only ,以便将您的自定义挂接安装在所有 bare repos。



你永远不会做的是直接将它复制到你的 bare-repo.git / hooks directory:这是gitolite发布常见钩子到所有裸回购的工作。

这样,您可以通过任何克隆 gitolite直接管理它们-admin 回购(回推回购会更新你可能拥有的任何钩子

所有裸回购意味着您的后期接收挂钩必须知道其操作的裸回购:

您可以通过 $ GIT_DIR
的值(设置为根 .git 在这个钩子运行的裸回购的目录)。

最后,对于这种 post-receive hook,请参阅 Git结帐在 post-receive hook:不是git仓库'。'

您需要明确地将 GIT_DIR GIT_WORK_TREE 定义到目的地为您的 git pull 取得成功。

  GIT_WORK_TREE = / Users /我/网站GIT_DIR = / Users / me / Sites / .git git pull 


After I push my local git repo to the server:

$ git push origin master

I want the bare repo on the server (after it received the push from me) to:

$ cd /Users/me/Sites
$ git pull
$ exit

I've looked at some questions here and they mention hooks in $HOME/gitolite/hooks,

but here's what I'm working with:

git@mm:gitolite $ pwd
/Users/git/gitolite
git@mm:gitolite $ ls
.git/                 README.txt            install*
CHANGELOG             check-g2-compat*      src/
COPYING               convert-gitosis-conf* t/

How do I add a post-receive hook for a specific bare repo?

If I go into my bare repo:

git@mm:bare-repo.git $ ls hooks
applypatch-msg.sample*     pre-rebase.sample*
commit-msg.sample*         prepare-commit-msg.sample*
post-update.sample*        update@
pre-applypatch.sample*     update.sample*
pre-commit.sample*

I don't see a post-receive hook. What gives?

解决方案

Update August 2013, with the latest gitolite: You now have official specific repo hook:

it's basically just creating a symlink in <repo.git>/hooks pointing to some file inside $rc{LOCAL_CODE}/hooks/repo-specific (except the gitolite-admin repo)


Original answer (

First, if you are using gitolite V3, you can define any hook, including a post-receive hook (except the update hook, see using hooks) : previously, with gitolite V2, pre-receive hook was reserved.

Now you can add a hook by copying it in the gitolite-admin/common/hooks local clone directory, and pushing gitolite-admin back to the gitolite server: gitolite will make sure that hook is declared for all bare repos it manages.

You can also add directly your hook on the server at a separate location designed by the $LOCAL_CODE "rc" variable ("rc" means defined in your gitolite.rc config file): $LOCAL_CODE/hooks/common. See "customizing gitolite".
The idea is to make sure a gitolite upgrade doesn't erase any of your custom programs.

Simply define a 'post-receive' file, executable (chmod 755), and copy it in the common/hooks directory of your choice (gitolite-admin local repo plus git push, or .gitolite on the server, or $LOCAL_CODE on the server).
Note: that fact that you don't see a 'post-receive.sample' file doesn't prevent you to define that hook.
If done directly on the server, you need then to run gitolite setup --hooks-only in order for your custom hooks to be setup on all bare repos.

What you would never do is to copy it directly on one of your bare-repo.git/hooks directory: that is the job of gitolite to publish "common" hooks to all your bare repo.
That way, you can manage them directly through any clone of gitolite-admin repo (pushing back that repo will update any hook that you might have changed).

"All bare repo" means your post-receive hook must know what bare repo it operates on:
You can do that by checking the value of $GIT_DIR (set to the root .git directory of the bare repo on which this hook is running).

Finally, for this kind of post-receive hook, see "Git checkout in post-receive hook: "Not a git repository '.'"":
You need to define GIT_DIR and GIT_WORK_TREE explicitly to the destination repo in order for your git pull to succeed.

 GIT_WORK_TREE=/Users/me/Sites GIT_DIR=/Users/me/Sites/.git git pull

这篇关于gitolite后接收特定裸露回购钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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