French translation: copy -> copie.
[git/dscho.git] / git-remote-testgit.py
blob740e02b1f343b576792480e50982b7afc6b42bc5
1 #!/usr/bin/env python
3 import sys
4 import os
5 sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
7 from git_remote_helpers.helper import RemoteHelper
8 from git_remote_helpers.util import check_output, debug
9 from git_remote_helpers.git.repo import GitRepo
10 from git_remote_helpers.git.exporter import GitExporter
11 from git_remote_helpers.git.importer import GitImporter
12 from git_remote_helpers.git.non_local import NonLocalGit
15 class TestgitRemoteHelper(RemoteHelper):
16 def get_repo(self, alias, url):
17 """Returns a git repository object initialized for usage.
18 """
20 repo = GitRepo(url)
21 repo.get_revs()
22 repo.get_head()
24 prefix = 'refs/testgit/%s/' % alias
25 debug("prefix: '%s'", prefix)
27 repo.marksfile = 'testgit.marks'
28 repo.prefix = prefix
30 self.setup_repo(repo, alias)
32 repo.exporter = GitExporter(repo)
33 repo.importer = GitImporter(repo)
34 repo.non_local = NonLocalGit(repo)
36 return repo
38 def local_repo(self, repo, path):
39 """Returns a git repository object initalized for usage.
40 """
42 local = GitRepo(path)
44 self.setup_local_repo(local, repo)
46 local.exporter = GitExporter(local)
47 local.importer = GitImporter(local)
49 return local
51 def do_list(self, repo, args):
52 """Lists all known references.
54 Bug: This will always set the remote head to master for non-local
55 repositories, since we have no way of determining what the remote
56 head is at clone time.
57 """
59 for ref in repo.revs_:
60 debug("? refs/heads/%s", ref)
61 print "? refs/heads/%s" % ref
63 if repo.head:
64 debug("@refs/heads/%s HEAD" % repo.head)
65 print "@refs/heads/%s HEAD" % repo.head
66 else:
67 debug("@refs/heads/master HEAD")
68 print "@refs/heads/master HEAD"
70 print # end list
72 def sanitize(self, value):
73 """Cleans up the url.
74 """
76 if value.startswith('testgit::'):
77 value = value[9:]
79 return value
81 def get_refs(self, repo, gitdir):
82 """Returns a dictionary with refs.
83 """
84 args = ["git", "--git-dir=" + gitdir, "for-each-ref", "refs/heads"]
85 lines = check_output(args).strip().split('\n')
86 refs = {}
87 for line in lines:
88 value, name = line.split(' ')
89 name = name.strip('commit\t')
90 refs[name] = value
91 return refs
94 if __name__ == '__main__':
95 sys.exit(TestgitRemoteHelper().main(sys.argv))