Git push 无法找到 repo 并退出代码为 128

Git push 无法找到 repo 并退出代码为 128

我正在使用 CentOS 5.5,需要在其上安装 git 服务器。

安装 git 并设置主目录:

yum install git
mkdir -p /home/git
cd /home/git/
chmod 777 -R . # yeah I know this is evil, but I want to make it work first...

已创建仓库:

repoName=test-repo
cd /home/git/
mkdir $repoName.git
cd $repoName.git
git --bare init
git update-server-info
chmod 777 -R .

已安装 gitweb:

yum install gitweb
cp -R /usr/share/gitweb/* /home/git/

(对于我来说,安装后 gitweb.cgi 位于 usr/share/gitweb 中)

改变了 gitweb 的配置:/etc/gitweb.conf:我们的 $projectroot = "/home/git";

最后将此配置添加到Apache:

<VirtualHost *:80>
     ServerAlias git.domian.com

     DocumentRoot  /home/git
     SetEnv        GITWEB_CONFIG   /etc/gitweb.conf

     <Directory /home/git>
          Order Allow,Deny
          Allow from all

          Options +ExecCGI
          AddHandler cgi-script .cgi
          DirectoryIndex gitweb.cgi
     </Directory>
</VirtualHost>

所以 gitweb 可以工作。克隆也可以工作(url 是http://git.domain.com/test-repo.git)但推送却给出:

git.exe push --progress  "origin" master:master

fatal: repository 'http://git.domain.com/test-repo.git/' not found


git did not exit cleanly (exit code 128) (62 ms @ 2015-02-09 17:31:29)

我尝试在 VirtualHost 配置中添加智能 HTTP 配置,如下所示:

SetEnv GIT_PROJECT_ROOT /home/git
SetEnv GIT_HTTP_EXPORT_ALL

ScriptAliasMatch \
    "(?x)^/(.*/(HEAD | \
                    info/refs | \
                    objects/(info/[^/]+ | \
                             [0-9a-f]{2}/[0-9a-f]{38} | \
                             pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                    git-(upload|receive)-pack))$" \
    /usr/libexec/git-core/git-http-backend/$1

但这只会将信息更改为:

fatal: unable to access 'http://git.domain.com/test-repo.git/': The requested URL returned error: 403

我还没有添加身份验证,那么问题是什么?

请帮忙。如果这不管用,我将不得不放弃 git 并转回 svn...

答案1

好的。所以这就像实际添加身份验证一样简单。因为我想使用 LDAP 身份验证(基于 Active Directory),所以我最终使用了以下内容...请注意,您的路径和密码可能会有所不同 ;-)

/etc/gitweb.conf

our $projectroot = "/home/git";

/etc/httpd/conf.vhosts/httpd-vhosts.conf

<VirtualHost *:80>
    Include conf.vhosts/git.conf
</VirtualHost>
# if you want HTTPS
<VirtualHost *:443>
    Include conf.vhosts/git.conf

    SSLEngine on
    SSLCertificateFile "/var/www/certs/subdomains-cert.pem"
    SSLCertificateKeyFile "/var/www/certs/subdomains-key.pem"
</VirtualHost>

/etc/httpd/conf.vhosts/git.conf

#
# Common
#
ServerAlias git.mol.com.pl

DocumentRoot  /home/git
SetEnv        GITWEB_CONFIG   /etc/gitweb.conf

<Directory /home/git>
    Order Allow,Deny
    Allow from all

    Options +ExecCGI
    AddHandler cgi-script .cgi
    DirectoryIndex gitweb.cgi
</Directory>

SetEnv GIT_PROJECT_ROOT /home/git
SetEnv GIT_HTTP_EXPORT_ALL

AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /home/git/$1
AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /home/git/$1
ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                        info/refs | \
                        objects/info/[^/]+ | \
                        git-(upload|receive)-pack))$" \
        /usr/libexec/git-core/git-http-backend/$1

<Location />
    AuthType Basic
    AuthBasicProvider ldap
    AuthBasicAuthoritative on
    AuthUserFile /dev/null
    AuthLDAPURL ldap://our.domain.server.com/CN=Users,DC=our,DC=domain,DC=server,DC=com?sAMAccountName
    AuthLDAPBindDN CN=someWindowsDomainUser,CN=Users,DC=our,DC=domain,DC=server,DC=com
    AuthLDAPBindPassword someWindowsDomainUserSecretPassword

    Order Allow,Deny
    Allow from all
</Location>

#
# Test repo
#
<Location /test-repo.git>
    AuthName "Test-bare-repo"

    require valid-user
</Location>

相关内容