4 from git_remote_helpers.util import check_call, check_output
7 class GitImporter(object):
8 """An importer for testgit repositories.
10 This importer simply delegates to git fast-import.
13 def __init__(self, repo):
14 """Creates a new importer for the specified repo.
19 def get_refs(self, gitdir):
20 """Returns a dictionary with refs.
22 args = ["git", "--git-dir=" + gitdir, "for-each-ref", "refs/heads"]
23 lines = check_output(args).strip().split('\n')
26 value, name = line.split(' ')
27 name = name.strip('commit\t')
31 def do_import(self, base):
32 """Imports a fast-import stream to the given directory.
34 Simply delegates to git fast-import.
37 dirname = self.repo.get_base_path(base)
39 gitdir = self.repo.gitpath
41 gitdir = os.path.abspath(os.path.join(dirname, '.git'))
42 path = os.path.abspath(os.path.join(dirname, 'git.marks'))
44 if not os.path.exists(dirname):
47 refs_before = self.get_refs(gitdir)
49 args = ["git", "--git-dir=" + gitdir, "fast-import", "--quiet", "--export-marks=" + path]
51 if os.path.exists(path):
52 args.append("--import-marks=" + path)
56 refs_after = self.get_refs(gitdir)
60 for name, value in refs_after.iteritems():
61 if refs_before.get(name) == value: