git_remote_helpers / git / importer.pyon commit git-remote-testgit: fix error handling (460d102)
   1import os
   2import subprocess
   3
   4from git_remote_helpers.util import check_call
   5
   6
   7class GitImporter(object):
   8    """An importer for testgit repositories.
   9
  10    This importer simply delegates to git fast-import.
  11    """
  12
  13    def __init__(self, repo):
  14        """Creates a new importer for the specified repo.
  15        """
  16
  17        self.repo = repo
  18
  19    def do_import(self, base):
  20        """Imports a fast-import stream to the given directory.
  21
  22        Simply delegates to git fast-import.
  23        """
  24
  25        dirname = self.repo.get_base_path(base)
  26        if self.repo.local:
  27            gitdir = self.repo.gitpath
  28        else:
  29            gitdir = os.path.abspath(os.path.join(dirname, '.git'))
  30        path = os.path.abspath(os.path.join(dirname, 'git.marks'))
  31
  32        if not os.path.exists(dirname):
  33            os.makedirs(dirname)
  34
  35        args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path]
  36
  37        if os.path.exists(path):
  38            args.append("--import-marks=" + path)
  39
  40        check_call(args)