How to solve 'invalid repo name' Git error

2019-02-19 01:53发布

问题:

I've installed Gitolite, just like said in GitLab instructions, til now it was all ok, repo's created... but when tried to clone or push, it returns NO repo found - or something similar.

But when I set my remote to the full path like git@server:22/~git/repositories/repo.git it clones, but when try to push, its caught an error:

git push origin master
ERROR: invalid repo name.
fatal: The remote end hung up unexpectedly

What can it be?

回答1:

That error message comes from "gitolite-shell.parse_soc()"

sub parse_soc {
    my $soc = $ENV{SSH_ORIGINAL_COMMAND};
    $soc ||= 'info';

    my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
    if ( $soc =~ m(^($git_commands) '/?(.*?)(?:\.git(\d)?)?'$) ) {
        my ( $verb, $repo, $trace_level ) = ( $1, $2, $3 );
        $ENV{D} = $trace_level if $trace_level;
        _die "invalid repo name: '$repo'" if $repo !~ $REPONAME_PATT;
        trace( 2, "git command", $soc );
        return ( $verb, $repo );
    }

With REPONAME_PATT being:

$REPONAME_PATT = qr(^\@?[0-9a-zA-Z][-0-9a-zA-Z._\@/+]*$);

A gitolite address shouldn't include any path, like so:

git@server:22/repo

Instead of git@server:22/~git/repositories/repo.git, this issue is described here:

Consider git@server:repositories/reponame.git.
The clone operation will work -- you're using the full Unix path, (assuming default $REPO_BASE setting), and so the shell finds the repo where you said it would be.
However, when you push, gitolite's update hook kicks in, and fails to run because some of the environment variables it is expecting are not present.