使用 gitosis 管理对 git 存储库的 http 访问

发布于 2024-09-19 11:47:37 字数 2454 浏览 5 评论 0原文

[更新 9/16/2010]

昨晚研究完这个问题后,我意识到我原来的问题实际上是问两个不同的问题:

1)是否可以为所有远程设置更新后挂钩由 gitosis 创建的存储库(即在 gitosis 中创建存储库后不必手动执行 mv hooks/post-update.sample hooks/post-update)这是通过 HTTP 克隆工作所必需的(哑HTTP 客户端依赖于从更新后挂钩内调用 git update-server-info 的事实。

2)一旦可以通过 HTTP 访问存储库,是否可以使用 gitosis.conf 中的选项打开和关闭访问(类似于 daemon = nogitweb = yes)

---问题1的解决方案---

事实证明,Git使用模板通过git init命令创建新的存储库。通过在模板目录中执行 mv hooks/post-update.sample hooks/post-update ,以后对我的服务器上的 git init 的所有调用都将具有更新后钩子配置正确。 (在 OSX 上,模板目录是 /opt/local/share/git-core/templates/ 对于那些关心的人)

此工作的另一个要求是打开 Apache 重写规则,以便 HTTP 克隆存储库的 URL 看起来像 http://git.example.com/repo.git

我在 /etc/apache2/extra/httpd-vhosts.conf 中的重写规则看起来像this:

# turning on mod rewrite
RewriteEngine on

# make the front page an internal rewrite to the gitweb script
RewriteRule ^/$ /cgi-bin/gitweb.cgi [L,PT]

# make access for "dumb clients" work
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT]

--- 仍在寻找问题 2 的解决方案...帮助! :) ---

现在 HTTP 克隆适用于我的所有存储库,我想知道是否有一种方法可以使用 gitosis 管理 HTTP 访问控制。设置 daemon = nogitweb = no 会关闭存储库的 git-daemon 和 gitweb 访问,但由于 Apache 重写规则仍然启用,该存储库仍然可以在 http://git.example.com/repo.git 克隆。关于如何使用 gitosis 来管理这个问题有什么想法吗?

[我最初发布的问题]

是否可以使用 gitosis 管理对 git 存储库的 http 访问?例如,在 gitosis.conf 中,我可以使用以下方式管理 gitweb 和 git-demon 的访问:

# Allow gitweb to show this repository.
gitweb = yes

# Allow git-daemon to publish this repository.
daemon = no

我目​​前可以通过发出以下命令来克隆我的存储库:

$ git clone git://git.example.com/repo.git

但是,当我发出以下命令时:

$ git clone http://git.example.com/repo.git

我收到以下错误消息:

fatal: http://git.example.com/repo.git/info/refs not found: did you run git update-server-info on the server?

但是,如果我登录到我的服务器并从 repo.git 中运行以下命令:

# From http://progit.org/book/ch4-5.html
$ cd project.git
$ mv hooks/post-update.sample hooks/post-update
$ chmod a+x hooks/post-update
$ git update-server-info

那么通过 http 克隆就可以正常工作。

有什么方法可以管理 gitosis 内对存储库的 http 访问吗?

[Update 9/16/2010]

After looking into this last night, I realized that my original question was really asking 2 separate things:

1) Is it possible to set the post-update hook for all remote repositories created by gitosis (i.e. not have to manually perform mv hooks/post-update.sample hooks/post-update for after creating a repository in gitosis) This is necessary for cloning via HTTP to work (dumb HTTP clients rely on the fact that git update-server-info is called from within the post-update hook).

2) Once the repository is accessible via HTTP, is it possible to turn access on and off using an option in gitosis.conf (something similar to daemon = no or gitweb = yes)

--- Solution to question 1 ---

It turns out that Git uses templates to create new repositories with the git init command. By performing mv hooks/post-update.sample hooks/post-update within the template directory, all future calls to git init on my server will have the post-update hook configured correctly. (On OSX the template directory is /opt/local/share/git-core/templates/ for those that care)

The other requirement for this to work is turning on Apache rewrite rules so that the HTTP clone URL for the repository looks like http//git.example.com/repo.git

My rewrite rules in /etc/apache2/extra/httpd-vhosts.conf look like this:

# turning on mod rewrite
RewriteEngine on

# make the front page an internal rewrite to the gitweb script
RewriteRule ^/$ /cgi-bin/gitweb.cgi [L,PT]

# make access for "dumb clients" work
RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT]

--- Still looking for a solution to question 2...HELP! :) ---

Now that HTTP cloning works for all my repositories, I'm wondering if there is a way to manage HTTP access control using gitosis. Setting daemon = no and gitweb = no turns off git-daemon and gitweb access for the repository, but since the Apache rewrite rules are still on, the repo is still clone-able at http://git.example.com/repo.git. Any ideas on how to use gitosis to manage this?

[The question I originally posted]

Is it possible to manage http access to git repositories using gitosis? For example, in gitosis.conf I can manage access for gitweb and git-demon using:

# Allow gitweb to show this repository.
gitweb = yes

# Allow git-daemon to publish this repository.
daemon = no

I'm currently able to clone my repository by issuing the following command:

$ git clone git://git.example.com/repo.git

However, when I issue the following command:

$ git clone http://git.example.com/repo.git

I get the following error message:

fatal: http://git.example.com/repo.git/info/refs not found: did you run git update-server-info on the server?

However, if I log into my server and run the following from within repo.git:

# From http://progit.org/book/ch4-5.html
$ cd project.git
$ mv hooks/post-update.sample hooks/post-update
$ chmod a+x hooks/post-update
$ git update-server-info

then cloning via http works fine.

Is there any way to manage http access to the repository from within gitosis?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

‘画卷フ 2024-09-26 11:47:37

gitweb 已经设置好并且可以工作了吗?查看此博客了解如何使用 gitweb 设置 gitosis 的说明。

顺便说一句,Gitolite 的主要特点是你可以拥有非常精细的权限。 IE。控制每个分支的权限。


更新:我认为 gitosis 与 gitweb 的集成基本上是它是否出现在项目列表中。它不控制gitweb的权限;这是通过网络服务器(apache)完成的。

Was gitweb already setup and working? Check this blog for instructions how to setup gitosis with gitweb.

BTW, Gitolite primary feature is that you can have very fine permissions. ie. control permission per branch.


UPDATE: I think gitosis integration w/ gitweb is basically whether it shows up on the project list. It doesn't control the permission to gitweb; that is done via web server (apache).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文