Add 'add' command to porcelain.
[jelmer/dulwich.git] / bin / dulwich
index 8565a7277800ec47c3802290318dfb206b7d9c49..3a7a610a7a5fcd0ac6eae03c40288a4d4a84f83a 100755 (executable)
@@ -30,20 +30,28 @@ import os
 import sys
 from getopt import getopt
 
+from dulwich import porcelain
 from dulwich.client import get_transport_and_path
 from dulwich.errors import ApplyDeltaError
 from dulwich.index import Index
 from dulwich.pack import Pack, sha_to_hex
 from dulwich.patch import write_tree_diff
 from dulwich.repo import Repo
-from dulwich.server import update_server_info
 
 
 def cmd_archive(args):
     opts, args = getopt(args, "", [])
     client, path = get_transport_and_path(args.pop(0))
+    location = args.pop(0)
     committish = args.pop(0)
-    client.archive(path, committish, sys.stdout.write, sys.stderr.write)
+    porcelain.archive(location, committish, outstream=sys.stdout,
+        errstream=sys.stderr)
+
+
+def cmd_add(args):
+    opts, args = getopt(args, "", [])
+
+    porcelain.add(".", paths=args)
 
 
 def cmd_fetch_pack(args):
@@ -159,52 +167,34 @@ def cmd_init(args):
     else:
         path = args[0]
 
-    if not os.path.exists(path):
-        os.mkdir(path)
-
-    if "--bare" in opts:
-        Repo.init_bare(path)
-    else:
-        Repo.init(path)
+    porcelain.init(path, bare=("--bare" in opts))
 
 
 def cmd_clone(args):
-    opts, args = getopt(args, "", [])
+    opts, args = getopt(args, "", ["bare"])
     opts = dict(opts)
 
     if args == []:
         print "usage: dulwich clone host:path [PATH]"
         sys.exit(1)
-    client, host_path = get_transport_and_path(args.pop(0))
 
+    source = args.pop(0)
     if len(args) > 0:
-        path = args.pop(0)
+        target = args.pop(0)
     else:
-        path = host_path.split("/")[-1]
+        target = None
 
-    if not os.path.exists(path):
-        os.mkdir(path)
-    r = Repo.init(path)
-    remote_refs = client.fetch(host_path, r,
-        determine_wants=r.object_store.determine_wants_all,
-        progress=sys.stdout.write)
-    r["HEAD"] = remote_refs["HEAD"]
+    porcelain.clone(source, target, bare=("--bare" in opts))
 
 
 def cmd_commit(args):
     opts, args = getopt(args, "", ["message"])
     opts = dict(opts)
-    r = Repo(".")
-    committer = "%s <%s>" % (os.getenv("GIT_COMMITTER_NAME"), 
-                             os.getenv("GIT_COMMITTER_EMAIL"))
-    author = "%s <%s>" % (os.getenv("GIT_AUTHOR_NAME"), 
-                          os.getenv("GIT_AUTHOR_EMAIL"))
-    r.do_commit(committer=committer, author=author, message=opts["--message"])
+    porcelain.commit(".", message=opts["--message"])
 
 
 def cmd_update_server_info(args):
-    r = Repo(".")
-    update_server_info(r)
+    porcelain.update_server_info(".")
 
 
 commands = {