summaryrefslogtreecommitdiff
path: root/git-remote-testgit.py
diff options
context:
space:
mode:
Diffstat (limited to 'git-remote-testgit.py')
-rw-r--r--git-remote-testgit.py75
1 files changed, 48 insertions, 27 deletions
diff --git a/git-remote-testgit.py b/git-remote-testgit.py
index df9d512..3dc4851 100644
--- a/git-remote-testgit.py
+++ b/git-remote-testgit.py
@@ -1,5 +1,18 @@
#!/usr/bin/env python
+# This command is a simple remote-helper, that is used both as a
+# testcase for the remote-helper functionality, and as an example to
+# show remote-helper authors one possible implementation.
+#
+# This is a Git <-> Git importer/exporter, that simply uses git
+# fast-import and git fast-export to consume and produce fast-import
+# streams.
+#
+# To understand better the way things work, one can activate debug
+# traces by setting (to any value) the environment variables
+# GIT_TRANSPORT_HELPER_DEBUG and GIT_DEBUG_TESTGIT, to see messages
+# from the transport-helper side, or from this example remote-helper.
+
# hashlib is only available in python >= 2.5
try:
import hashlib
@@ -35,7 +48,7 @@ def get_repo(alias, url):
prefix = 'refs/testgit/%s/' % alias
debug("prefix: '%s'", prefix)
- repo.gitdir = ""
+ repo.gitdir = os.environ["GIT_DIR"]
repo.alias = alias
repo.prefix = prefix
@@ -70,9 +83,19 @@ def do_capabilities(repo, args):
print "import"
print "export"
- print "gitdir"
print "refspec refs/heads/*:%s*" % repo.prefix
+ dirname = repo.get_base_path(repo.gitdir)
+
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+
+ path = os.path.join(dirname, 'testgit.marks')
+
+ print "*export-marks %s" % path
+ if os.path.exists(path):
+ print "*import-marks %s" % path
+
print # end capabilities
@@ -121,8 +144,24 @@ def do_import(repo, args):
if not repo.gitdir:
die("Need gitdir to import")
+ ref = args[0]
+ refs = [ref]
+
+ while True:
+ line = sys.stdin.readline()
+ if line == '\n':
+ break
+ if not line.startswith('import '):
+ die("Expected import line.")
+
+ # strip of leading 'import '
+ ref = line[7:].strip()
+ refs.append(ref)
+
repo = update_local_repo(repo)
- repo.exporter.export_repo(repo.gitdir)
+ repo.exporter.export_repo(repo.gitdir, refs)
+
+ print "done"
def do_export(repo, args):
@@ -132,32 +171,15 @@ def do_export(repo, args):
if not repo.gitdir:
die("Need gitdir to export")
- dirname = repo.get_base_path(repo.gitdir)
-
- if not os.path.exists(dirname):
- os.makedirs(dirname)
-
- path = os.path.join(dirname, 'testgit.marks')
- print path
- if os.path.exists(path):
- print path
- else:
- print ""
- sys.stdout.flush()
-
update_local_repo(repo)
- repo.importer.do_import(repo.gitdir)
- repo.non_local.push(repo.gitdir)
-
-
-def do_gitdir(repo, args):
- """Stores the location of the gitdir.
- """
+ changed = repo.importer.do_import(repo.gitdir)
- if not args:
- die("gitdir needs an argument")
+ if not repo.local:
+ repo.non_local.push(repo.gitdir)
- repo.gitdir = ' '.join(args)
+ for ref in changed:
+ print "ok %s" % ref
+ print
COMMANDS = {
@@ -165,7 +187,6 @@ COMMANDS = {
'list': do_list,
'import': do_import,
'export': do_export,
- 'gitdir': do_gitdir,
}