Sunday, August 24, 2008

Install Git/Gitosis on a server (Debian) - Part 2

So I ran into some more issues before getting my Git hosting (via Gitosis) all working.

The first hurdle was getting past an error thrown when attempting to do a `git clone` of the gitosis-admin repository. The error was being thrown by os.py (remember that gitosis-admin is python based). The error message looked like this:

Traceback (most recent call last):

File ”/usr/bin/gitosis-serve”, line 7, in ?
sys.exit( File ”/usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg/gitosis/app.py”, line 24, in run return app.main()
File ”/usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg/gitosis/app.py”, line 38, in main self.handle_args(parser, cfg, options, args)
File ”/usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg/gitosis/serve.py”, line 205, in handle_args os.execvp(‘git-shell’, [‘git-shell’, ‘-c’, newcmd])
File ”/usr/lib/python2.4/os.py”, line 341, in execvp _execvpe(file, args) File ”/usr/lib/python2.4/os.py”, line 379, in _execvpe func(fullname, *argrest)
OSError: [Errno 2] No such file or directory
The root cause of this is that the executable `git-shell` is missing from your install directory (be /usr/bin or /usr/local/bin). I've done a install locally and all the 140-some executables were places in my install directory (/usr/bin).

Originally, I just copied `git-shell` into /usr/bin. That's hack-ish, what I ended up doing was creating a symlink to `git-shell` from where I have git (in my case, /opt/git-1.6.0, with a symlink to it named /opt/git).

So now we can do our clone of the repository:

`git clone git@YOUR_SERVER:gitosis-admin.git`

This appears in both tutorials I looked at [urban puddle] [scie.nti.st]

Now we want to create a new repository. That was my next hurdle; and you won't need to overcome it if you follow directions. Notably, the simple directions in either. Which is that you need to modify the gitosis.conf (which is Step 6 in the Urban Puddle tutorial and "Creating new repositories" in the scie.nti.st tutorial).

I attempted to simply do something like initialize a git repository, do some commits, add a remote (origin) to the server, and then push to that remote (origin).

If you have gone awry - like me - you'll run into the following error:

ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

If you add the following under [gitosis] in the gitosis.conf:

loglevel = DEBUG

You'll get some helpful debug output.
lenards@deedee:~/devel/cs453/project$ git push origin master:refs/heads/master
DEBUG:gitosis.serve.main:Got command "git-receive-pack 'cs453-project.git'"
DEBUG:gitosis.access.haveAccess:Access check for 'lenards@deedee' as 'writable' on 'cs453-project.git'...
DEBUG:gitosis.access.haveAccess:Stripping .git suffix from 'cs453-project.git', new value 'cs453-project'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'gitosis-admin'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'cs453-project'
DEBUG:gitosis.access.haveAccess:Access check for 'lenards@deedee' as 'writeable' on 'cs453-project.git'...
DEBUG:gitosis.access.haveAccess:Stripping .git suffix from 'cs453-project.git', new value 'cs453-project'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'gitosis-admin'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'cs453-project'
DEBUG:gitosis.access.haveAccess:Access check for 'lenards@deedee' as 'readonly' on 'cs453-project.git'...
DEBUG:gitosis.access.haveAccess:Stripping .git suffix from 'cs453-project.git', new value 'cs453-project'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'gitosis-admin'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'cs453-project'
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly
I missed the step in the directions about adding a new group to the gitosis.conf, which is why when doing your `git push origin master:refs/heads/master` it complains about not have readonly access. There is *no* group to access, so you don't have writable or readonly access.

After doing Step 6 from Urban Puddle tutorial - I was able to push my new repository for my compiler project.

I hope this helps someone.

Andy

14 comments:

Jamie Border said...

Yeah, I suffered from this, but there was a different source - gitosis lives in /home for me and I had /home mounted 'noexec'.

This stopped the post-commit hook from running. AFAIK 'defaults' also gives this behaviour, so using 'exec' as an option in /etc/fstab makes everything good.

Ilia Lobsanov said...

how did you setup debugging? I added "loglevel=DEBUG" as you said in gitosis.conf, committed and pushed it. then I tried pushing another repo to the gitosis server and I didn't get any debug messages

Ilia Lobsanov said...

figured it out. see http://twitter.com/ilia/status/1127369036

Unknown said...

My problem was I didn't do Step 5... :(

Kevin said...

I also forgot to put a new repo line in the conf file before trying to push a new git repository.

Thanks for the help.

Reuven said...

I can't get git to work! I can edit my gitosis-config and push it back without a problem, but when I try to create a new repository, and push it back, I always get the error ERROR:gitosis.serve.main:Repository read access denied

My keys are fine, (ssh -v connects) and I can edit and push gtosis-config. Does git actually work for anyone?

Reuven said...

Oh, and where does that alleged "debug output" show up?

valerius said...

loglevel=DEBUG is not working because you have to write it with spaces:
loglevel = DEBUG

jeff said...

Reuven, I had the same problem, and found that I had to add a [repo myProject] section to gitosis.conf, like this: http://www.mantisbt.org/wiki/doku.php/mantisbt:gitosis_management#adding_a_new_repository

Jonas said...

I also got the error trying to push my first repository:

ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

This can also be fixed by making the python bindings executable with the following line:

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

Adam Guthrie said...

I was getting this error even after added a new repository to gitosis.conf and pushing the changes.

Turns out that none of my changes were taking effect because the post-update file was a symlink pointing to a non-existent file!

I installed gitosis in Ubuntu 9.04 and I guess when I upgraded to 9.10 the symlink wasn't updated.

After I updated the symlink to post-update and pushed a new change to gitosis-admin, everything worked fine:

ln -fs `dpkg-query -L gitosis |grep post-update` /srv/gitosis/repositories/gitosis-admin.git/hooks/post-update

cori said...

I had a similar problem, and it took me quite a while to realize that I had misspelled "writable" in my gitosis.conf entry for the new repo. Just in case anyone else is as bone-headed as I was - make sure to check your spelling ;)

Dennis Fel T. Matutina said...

I have created a different group aside gitosis-admin, which did not work.

When I added myself to the gitosis-admin group and made the test repo writable in gitosis.conf, everything went fine.

I think this is a bug in Ubuntu Jaunty implementation of gitosis

plaster1 said...

step 6 had to take place on the git SERVER's gitosis.conf

sudo nano /home/git/.gitosis.conf


then add:

[group myrailsapp]
members = vince@urbanpuddle
writable = myrailsapp