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.
24 prefix
= 'refs/testgit/%s/' % alias
25 debug("prefix: '%s'", prefix
)
27 repo
.marksfile
= 'testgit.marks'
30 self
.setup_repo(repo
, alias
)
32 repo
.exporter
= GitExporter(repo
)
33 repo
.importer
= GitImporter(repo
)
34 repo
.non_local
= NonLocalGit(repo
)
38 def local_repo(self
, repo
, path
):
39 """Returns a git repository object initalized for usage.
44 self
.setup_local_repo(local
, repo
)
46 local
.exporter
= GitExporter(local
)
47 local
.importer
= GitImporter(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.
60 debug("? refs/heads/%s", ref
)
61 print "? refs/heads/%s" % ref
64 debug("@refs/heads/%s HEAD" % repo
.head
)
65 print "@refs/heads/%s HEAD" % repo
.head
67 debug("@refs/heads/master HEAD")
68 print "@refs/heads/master HEAD"
72 def sanitize(self
, value
):
76 if value
.startswith('testgit::'):
81 def get_refs(self
, repo
, gitdir
):
82 """Returns a dictionary with refs.
84 args
= ["git", "--git-dir=" + gitdir
, "for-each-ref", "refs/heads"]
85 lines
= check_output(args
).strip().split('\n')
88 value
, name
= line
.split(' ')
89 name
= name
.strip('commit\t')
94 if __name__
== '__main__':
95 sys
.exit(TestgitRemoteHelper().main(sys
.argv
))