0

I'm trying to initialize a git repo and then serve it using the git daemon. Everything with GitPython.

Initializing the repo works:

temp_dir = '/tmp/something'
repo = git.Repo.init(temp_dir)

Starting the daemon as well:

gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT,as_process=True, export_all=True)
gd.proc.wait()

But I'm not able to access the repo:

git clone git://127.0.0.1:9418/something 
Cloning into 'something'...
fatal: remote error: access denied or repository not exported: /something

I'm not sure if I have to initialize the repo as bare, or if I have to specify the base_path when starting the git daemon... tried it all. Does anybody have some pointers?

PS: I've seen a similar approach here: https://github.com/gitpython-developers/GitPython/blob/master/git/test/lib/helper.py

fractalwrench
  • 4,028
  • 7
  • 33
  • 49
  • Looks like the repository should [be exported](https://github.com/gitpython-developers/GitPython/search?utf8=%E2%9C%93&q=daemon_export), that is a file [git-daemon-export-ok](https://git-scm.com/book/en/v2/Git-on-the-Server-Git-Daemon) is created within `git_dir`. Take a look at [_set_daemon_export()](https://github.com/gitpython-developers/GitPython/blob/29724818764af6b4d30e845d9280947584078aed/git/repo/base.py#L531) function – user3159253 Jun 04 '16 at 10:05
  • So, I guess `repo.daemon_export = True` would solve your problem – user3159253 Jun 04 '16 at 10:07
  • Thanks! figured it out. – martialblog Jun 05 '16 at 09:26

1 Answers1

0

Figured it out, Thanks to user3159253.

import git
import tempfile

tmpdir = tempfile.TemporaryDirectory(suffix='.git')
repo = git.Repo.init(tmpdir.name, shared=True, bare=True)
repo.daemon_export = True

gd = git.Git().daemon(tmpdir.name,
                      enable='receive-pack',
                      listen='127.0.0.1',
                      port=9418,
                      as_process=True,
                      verbose=True
)
gd.proc.wait()

Now you can clone that repo using:

$git clone git://127.0.0.1:9418/tmp/<name-of-tmpdir>.git