Ver código fonte

Add -b argument to dulwich clone.

Jelmer Vernooij 2 anos atrás
pai
commit
c67d2ed684
4 arquivos alterados com 20 adições e 7 exclusões
  1. 3 0
      NEWS
  2. 6 1
      dulwich/cli.py
  3. 2 1
      dulwich/client.py
  4. 9 5
      dulwich/porcelain.py

+ 3 - 0
NEWS

@@ -1,5 +1,8 @@
 0.20.47	UNRELEASED
 
+ * Add -b argument to ``dulwich clone``.
+   (Jelmer Vernooij)
+
  * On Windows, provide a hint about developer mode
    when creating symlinks fails due to a permission
    error. (Jelmer Vernooij, #1005)

+ 6 - 1
dulwich/cli.py

@@ -247,6 +247,10 @@ class cmd_clone(Command):
         parser.add_option(
             "--depth", dest="depth", type=int, help="Depth at which to fetch"
         )
+        parser.add_option(
+            "-b", "--branch", dest="branch", type=str,
+            help=("Check out branch instead of branch pointed to by remote "
+                  "HEAD"))
         options, args = parser.parse_args(args)
 
         if args == []:
@@ -259,7 +263,8 @@ class cmd_clone(Command):
         else:
             target = None
 
-        porcelain.clone(source, target, bare=options.bare, depth=options.depth)
+        porcelain.clone(source, target, bare=options.bare, depth=options.depth,
+                        branch=options.branch)
 
 
 class cmd_commit(Command):

+ 2 - 1
dulwich/client.py

@@ -1397,7 +1397,8 @@ class SubprocessGitClient(TraditionalGitClient):
 class LocalGitClient(GitClient):
     """Git Client that just uses a local Repo."""
 
-    def __init__(self, thin_packs=True, report_activity=None, config=None):
+    def __init__(self, thin_packs=True, report_activity=None,
+                 config: Optional[Config] = None):
         """Create a new LocalGitClient instance.
 
         Args:

+ 9 - 5
dulwich/porcelain.py

@@ -89,6 +89,7 @@ from dulwich.client import (
     get_transport_and_path,
 )
 from dulwich.config import (
+    Config,
     ConfigFile,
     StackedConfig,
     read_submodules,
@@ -496,10 +497,10 @@ def clone(
     checkout=None,
     errstream=default_bytes_err_stream,
     outstream=None,
-    origin="origin",
-    depth=None,
-    branch=None,
-    config=None,
+    origin: Optional[str] = "origin",
+    depth: Optional[int] = None,
+    branch: Optional[Union[str, bytes]] = None,
+    config: Optional[Config] = None,
     **kwargs
 ):
     """Clone a local or remote git repository.
@@ -539,6 +540,9 @@ def clone(
     if target is None:
         target = source.split("/")[-1]
 
+    if isinstance(branch, str):
+        branch = branch.encode(DEFAULT_ENCODING)
+
     mkdir = not os.path.exists(target)
 
     (client, path) = get_transport_and_path(
@@ -1709,7 +1713,7 @@ def fetch(
     return fetch_result
 
 
-def ls_remote(remote, config=None, **kwargs):
+def ls_remote(remote, config: Optional[Config] = None, **kwargs):
     """List the refs in a remote.
 
     Args: