使用git守护程序和GitPython服务存储库

时间:2016-06-04 08:32:55

标签: python 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

我不确定是否必须将repo初始化为裸机,或者在启动git守护程序时必须指定base_path ...尝试了所有操作。有人有指点吗?

PS:我在这里看到了类似的方法: https://github.com/gitpython-developers/GitPython/blob/master/git/test/lib/helper.py

1 个答案:

答案 0 :(得分:0)

想出来,感谢user3159253。

$images = $_FILES['images'];

foreach($images['name'] as $key => $value) {

     $file_name[$key] = $value;
     $file_tmp = $images['tmp_name'][$key];

     $file_ext = explode('.', $file_name); // images.jpg becomes images jpg
     $file_ext = strtolower(end($file_ext)); // We make the extension (jpg, gif etc.)
     // lowercase and separate it with "end" from images, which leaves us the extension

     $file_trim_name = rtrim($file_name, ".".$file_ext); // We remove the extension (.jpg)
     // from the image name

     $file_name_new = uniqid($file_trim_name . "-", true) . '.' . $file_ext; // Create a
     // "uniqid" (if you do not want to overwrite other images). We take the image name
     // and separate name and id by "-" and add the extension afterwards: $file_name_new = images-20302.jpg

     $file_destination = 'image/folder/location' . $file_name_new; // Choose file location

     move_uploaded_file($file_tmp, $file_destination); // Here we move images to their
     // location with the function "move_uploaded_file"

}

$url1 = $file_destination[0]; // Selecting first image
$url2 = $file_destination[1]; // Selecting second image

$query_images = "INSERT INTO images (url1, url2)

VALUES

('{$url1}', '{$url2}'";

现在您可以使用以下方法克隆该回购:

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()