开源项目 GitLab 的项目 ssh 地址和 ssh 方式 push 问题

mmap · 2013年03月20日 · 最后由 changming 回复于 2014年06月21日 · 53494 次阅读

在一台内网服务器上安装 gitlab 4.2 stable, 按照https://github.com/gitlabhq/gitlabhq/blob/4-2-stable/doc/install/installation.md 安装完后,运行 sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production 全部绿色通过。 启动时/etc/init.d/gitlab 脚本运行有问题,因此改为按 sudo -u gitlab -H bundle exec unicorn_rails -c $DAEMON_OPTS -E production& 启动,启动后页面显示,创建新用户,登录,创建新组织,新项目等均正常。 问题在于: 新建一个名为 test 的项目后,在另一台机器(与服务器处于同一内网)按照 gitlab 给出的 test 项目 ssh 地址,运行 git clone [email protected]:test/test.git 会提示 fatal: 'test/test.git' does not appear to be a git repository 猜测可能是目录位置不对,于是运行 git clone [email protected]:repositories/test/test.git 可以成功 clone(提示 Cloning into 'test'... warning: You appear to have cloned an empty repository.) 但是会出现第二个问题 在 git init 随便 commit 一个文件后 push 回 server 时 会提示 Counting objects: 3, done. Writing objects: 100% (3/3), 197 bytes, done. Total 3 (delta 0), reused 0 (delta 0) remote: Empty compile time value given to use lib at hooks/update line 10 remote: Use of uninitialized value in require at hooks/update line 11. remote: Can't locate Gitolite/Hooks/Update.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at hooks/update line 11. remote: BEGIN failed--compilation aborted at hooks/update line 11. remote: error: hook declined to update refs/heads/master To [email protected]:repositories/test/test.git ! [remote rejected] master -> master (hook declined) error: failed to push some refs to '[email protected]:repositories/test/test.git'

我搜索到了 5 个月前的一个类似问题https://github.com/gitlabhq/gitlabhq/pull/1719#issuecomment-9731139 按照@saito的建议,运行 sudo usermod -a -G gitlab git 也没能解决问题

我把 gitlab.yml 中与 gitolite 有关的部分贴出来,请大家帮忙看下有什么问题

Gitolite settings

gitolite: admin_uri: git@localhost:gitolite-admin

# REPOS_PATH MUST NOT BE A SYMLINK!!! repos_path: /home/git/repositories/ hooks_path: /home/git/.gitolite/hooks/ admin_key: gitlab upload_pack: true receive_pack: true ssh_user: git ssh_host: 192.168.1.254 # ssh_port: 22 # config_file: gitolite.conf

# Uncomment and customize if you can't use the default group to own the repositories and run Gitolite (default: same as the 'ssh_user' above) # owner_group: group123

Gitlab 的 gitolite 是我 patch 过的,如果你使用的是官方的版本,可能会导致 update hook 有问题。

其实已经 push 成功了,但是运行 gitolite 的 hook 失败了。

你可以看一下 Repo 内的 hook, 是否存在 gitolite 的 update hook. 再一个可以看一下你的 gitolite 安装的位置,有可能 update hook 没有找到 gitolite 的 home.

@Saito 谢谢快速回复! 我去检查一下 repo 的 hook。 另外,我很奇怪的是 gitlab 显示的项目 ssh 地址为什么不是 [email protected]:repositories/test/test.git 而是 [email protected]:test/test.git

#2 楼 @mmap 我怀疑是你的 gitlab.yml 文件的 Repositories 地址配置有问题。

你可以看看 gitlab.yml 里面配置的地址,跟你真实的地址:/home/git/repositories/repositories/test/test 是不是这样的?

@Saito 不是 repo 的真实地址就是/home/git/repositories/test/test.git 顺便 l /home/git/repositories/test/test.git/hooks得出 post-receive -> /home/git/.gitolite/hooks/common/post-receive update -> /home/git/.gitolite/hooks/common/update 而/home/git/.gitolite/hooks/common/update 和/home/git/.gitolite/hooks/common/post-receive 均存在 忘了说 服务器的 git 用户是之前就存在的 不知道这有没有影响。

#4 楼 @mmap https://github.com/gitlabhq/gitlabhq/blob/4-2-stable/doc/install/installation.md#test-if-everything-works-so-far

先试试在这里是不是就需要加 repositories. 如果是的话检查一下自己的 Gitolite .

运行 sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin 得到 Cloning into /tmp/gitolite-admin... Warning: Permanently added 'localhost' (RSA) to the list of known hosts. remote: Counting objects: 34, done. remote: Compressing objects: 100% (25/25), done. remote: Total 34 (delta 6), reused 0 (delta 0) Receiving objects: 100% (34/34), 3.07 KiB, done. Resolving deltas: 100% (6/6), done.

@Saito 看起来不需要

#6 楼 @mmap 这个还真没碰到过这种情况了.. 问题就在 Gitolite 上,但是不知道怎么解决.. Sorry..

https://github.com/gitlabhq/gitlabhq/wiki/From-4.2-to-5.0 往 5.0 升级吧.. 平生最恨的就是 gitolite 了。

@Saito many thanks.我都没指望能在这得到回复。https://github.com/gitlabhq/gitlabhq/issues?state=open 现在有 429 个 open issue,估计 gitlab 工作人员都忙不过来了

#7 楼 @Saito 升级到 5.0 stable 这两个蛋疼的问题都没有了!!!

#7 楼 @Saito 是你不用 Twisted ...

gitlab-shell 好像也有问题,问题在 5.2 中好像又回来了。HTTP clone 工作,SSH clone 需要加 repositories 目录。

git clone [email protected]:test/test.git fatal: 'test/test.git' does not appear to be a git repository fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

git clone [email protected]:repositories/test/test.git 可以成功 clone

@mmap @Saito 阅读了代码,结合这里的问题描述解决了 ssh clone 问题: https://github.com/gitlabhq/gitlabhq/issues/3686

当你在一个已经设置~/.ssh/authorized_keys 的服务器上安装 Gitlab 时,你需要备份这个文件,然后运行下面的 rake,告诉用户在 ssh clone 时用 gitlab-shell 就行了:

bunde exec rake gitlab:shell:setup RAILS_ENV=production

系统默认使用的是 git-shell, 那样 ssh clone 时必须要使用加了 repositories 目录的结对路径。

fatal: '/home/git/repositories/alex/test.git' does not appear to be a git repository fatal: Could not read from remote repository 我新建了一个项目 test.git,在执行到最后一步(git push -u origin master) 时出现了上述错误,搜了很多,都没能解决,请指教,谢谢! 到服务器端看了下/home/git/repositories/alex/下面是没有 test.git,这个是要 push 成功才会存在的吧?

或许是权限问题。

cd $HOME
chmod go-rwx .
chmod -R go-rwx .ssh

http://gitolite.com/gitolite/sts.html#stsapp1

16 楼 已删除

#14 楼 @alexbai 请问下,你这个问题解决没有?如何做的?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号