Skip to content

Commit

Permalink
dirty git checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jun 20, 2021
1 parent cdc9cb5 commit 0a084bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
22 changes: 8 additions & 14 deletions sphinx_multiversion/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import tarfile
import tempfile
import shutil

GitRef = collections.namedtuple(
"VersionRef",
Expand Down Expand Up @@ -154,17 +155,10 @@ def file_exists(gitroot, refname, filename):


def copy_tree(gitroot, src, dst, reference, sourcepath="."):
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)
try:
shutil.copytree(gitroot, dst)
except OSError as e:
if e.errno == 17: # already copied
return
raise
subprocess.call(("git", "checkout", "-f", reference.commit), cwd=dst)
5 changes: 3 additions & 2 deletions sphinx_multiversion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ def main(argv=None):
repopath = os.path.join(tmp, gitref.commit)
try:
git.copy_tree(str(gitroot), gitroot.as_uri(), repopath, gitref)
except (OSError, subprocess.CalledProcessError):
except (OSError, subprocess.CalledProcessError) as e:
logger.error(
"Failed to copy git tree for %s to %s",
"Failed to copy git tree for %s to %s:\n%s",
gitref.refname,
repopath,
e,
)
continue

Expand Down

0 comments on commit 0a084bb

Please sign in to comment.