Holzhaus / sphinx-multiversion

Sphinx extension for building self-hosted versioned docs.
https://holzhaus.github.io/sphinx-multiversion/
BSD 2-Clause "Simplified" License
148 stars 65 forks source link

Temp clone of git remote branches are not in a repository #109

Open andrew-fennell opened 6 months ago

andrew-fennell commented 6 months ago

There is an issue where remote branch configs cannot be loaded. After digging deeper into this issue, I found that there was a git command being ran, but it threw an error saying it was not in a git repository. This was in the /tmp/... directory created.

The issue seems to be that remote branches in git.py are created using the function copy_tree(gitroot, src, dst, reference, sourcepath="."), which creates the git repository shown in the following code:

with tempfile.SpooledTemporaryFile() as fp:
        cmd = (
            "git",
            "archive",
            "--format",
            "tar",
            reference.commit,
            "--",
            sourcepath,
        )
        subprocess.check_call(cmd, cwd=gitroot, stdout=fp)
        fp.seek(0)
        with tarfile.TarFile(fileobj=fp) as tarfp:
            tarfp.extractall(dst)

This ultimately causes this error to be thrown in main.py (line 245):

                   "Failed load config for %s from %s",
                   gitref.refname,
                   confpath,
               )

A simple fix would be to add git init right after the first code snippet in git.py.

cmd = (
        "git",
        "init"
    )
    subprocess.check_call(cmd, cwd=dst)