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