Explorar o código

porcelain: add ls-remote equivalent using client.get_refs

Mike Edgar %!s(int64=9) %!d(string=hai) anos
pai
achega
ef48e2cb77
Modificáronse 2 ficheiros con 17 adicións e 0 borrados
  1. 11 0
      bin/dulwich
  2. 6 0
      dulwich/porcelain.py

+ 11 - 0
bin/dulwich

@@ -342,6 +342,16 @@ def cmd_status(args):
         sys.stdout.write("\n")
 
 
+def cmd_ls_remote(args):
+    opts, args = getopt(args, '', [])
+    if len(args) < 1:
+        print('Usage: dulwich ls-remote URL')
+        sys.exit(1)
+    refs = porcelain.ls_remote(args[0])
+    for ref in sorted(refs):
+        sys.stdout.write("%s\t%s\n" % (ref, refs[ref]))
+
+
 commands = {
     "add": cmd_add,
     "archive": cmd_archive,
@@ -357,6 +367,7 @@ commands = {
     "fetch": cmd_fetch,
     "init": cmd_init,
     "log": cmd_log,
+    "ls-remote": cmd_ls_remote,
     "receive-pack": cmd_receive_pack,
     "reset": cmd_reset,
     "rev-list": cmd_rev_list,

+ 6 - 0
dulwich/porcelain.py

@@ -29,6 +29,7 @@ Currently implemented:
  * diff-tree
  * fetch
  * init
+ * ls-remote
  * pull
  * push
  * rm
@@ -762,3 +763,8 @@ def fetch(repo, remote_location, outstream=sys.stdout, errstream=sys.stderr):
         client, path = get_transport_and_path(remote_location)
         remote_refs = client.fetch(path, r, progress=errstream.write)
     return remote_refs
+
+
+def ls_remote(remote):
+    client, host_path = get_transport_and_path(remote)
+    return client.get_refs(host_path)