![](/img/trans.png)
[英]GitPython — How to 'git stash' changes to a GitPython repository?
[英]Serve repository using git daemon with GitPython
我正在嘗試初始化git repo,然后使用git守護進程將其提供。 GitPython的一切。
初始化回購工作:
temp_dir = '/tmp/something'
repo = git.Repo.init(temp_dir)
也啟動守護程序:
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()
但是我無法訪問該存儲庫:
git clone git://127.0.0.1:9418/something
Cloning into 'something'...
fatal: remote error: access denied or repository not exported: /something
我不確定是否必須將存儲庫初始化為裸露,或者在啟動git守護程序時是否必須指定base_path ...嘗試了所有。 有人有指針嗎?
PS:我在這里看到了類似的方法: https : //github.com/gitpython-developers/GitPython/blob/master/git/test/lib/helper.py
弄清楚了,這要感謝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()
現在,您可以使用以下命令克隆該存儲庫:
$git clone git://127.0.0.1:9418/tmp/<name-of-tmpdir>.git
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.