Browse Source

Pass in config when running operations from porcelain. Fixes #545

Jelmer Vernooij 7 years ago
parent
commit
698dc4d033
4 changed files with 26 additions and 7 deletions
  1. 5 0
      NEWS
  2. 3 2
      dulwich/client.py
  3. 4 0
      dulwich/config.py
  4. 14 5
      dulwich/porcelain.py

+ 5 - 0
NEWS

@@ -1,5 +1,10 @@
 0.18.3	UNRELEASED
 
+ BUG FIXES
+
+  * Read config during porcelain operations that involve remotes.
+    (Jelmer Vernooij, #545)
+
 0.18.2	2017-08-01
 
  TEST FIXES

+ 3 - 2
dulwich/client.py

@@ -833,7 +833,7 @@ class SubprocessGitClient(TraditionalGitClient):
 class LocalGitClient(GitClient):
     """Git Client that just uses a local Repo."""
 
-    def __init__(self, thin_packs=True, report_activity=None):
+    def __init__(self, thin_packs=True, report_activity=None, config=None):
         """Create a new LocalGitClient instance.
 
         :param thin_packs: Whether or not thin packs should be retrieved
@@ -1019,7 +1019,8 @@ get_ssh_vendor = SubprocessSSHVendor
 
 class SSHGitClient(TraditionalGitClient):
 
-    def __init__(self, host, port=None, username=None, vendor=None, **kwargs):
+    def __init__(self, host, port=None, username=None, vendor=None,
+                 config=None, **kwargs):
         self.host = host
         self.port = port
         self.username = username

+ 4 - 0
dulwich/config.py

@@ -387,6 +387,10 @@ class StackedConfig(Config):
     def __repr__(self):
         return "<%s for %r>" % (self.__class__.__name__, self.backends)
 
+    @classmethod
+    def default(cls):
+        return cls(cls.default_backends())
+
     @classmethod
     def default_backends(cls):
         """Retrieve the default configuration.

+ 14 - 5
dulwich/porcelain.py

@@ -69,6 +69,9 @@ from dulwich.archive import (
 from dulwich.client import (
     get_transport_and_path,
     )
+from dulwich.config import (
+    StackedConfig,
+    )
 from dulwich.diff_tree import (
     CHANGE_ADD,
     CHANGE_DELETE,
@@ -283,7 +286,9 @@ def clone(source, target=None, bare=False, checkout=None,
         checkout = (not bare)
     if checkout and bare:
         raise ValueError("checkout and bare are incompatible")
-    client, host_path = get_transport_and_path(source)
+
+    config = StackedConfig.default()
+    client, host_path = get_transport_and_path(source, config=config)
 
     if target is None:
         target = host_path.split("/")[-1]
@@ -742,7 +747,8 @@ def push(repo, remote_location, refspecs,
     with open_repo_closing(repo) as r:
 
         # Get the client and path
-        client, path = get_transport_and_path(remote_location)
+        client, path = get_transport_and_path(
+                remote_location, config=r.get_config_stack())
 
         selected_refs = []
 
@@ -796,7 +802,8 @@ def pull(repo, remote_location=None, refspecs=None,
             selected_refs.extend(
                 parse_reftuples(remote_refs, r.refs, refspecs))
             return [remote_refs[lh] for (lh, rh, force) in selected_refs]
-        client, path = get_transport_and_path(remote_location)
+        client, path = get_transport_and_path(
+                remote_location, config=r.get_config_stack())
         remote_refs = client.fetch(
             path, r, progress=errstream.write, determine_wants=determine_wants)
         for (lh, rh, force) in selected_refs:
@@ -1032,7 +1039,8 @@ def fetch(repo, remote_location, outstream=sys.stdout,
     :return: Dictionary with refs on the remote
     """
     with open_repo_closing(repo) as r:
-        client, path = get_transport_and_path(remote_location)
+        client, path = get_transport_and_path(
+                remote_location, config=r.get_config_stack())
         remote_refs = client.fetch(path, r, progress=errstream.write)
     return remote_refs
 
@@ -1043,7 +1051,8 @@ def ls_remote(remote):
     :param remote: Remote repository location
     :return: Dictionary with remote refs
     """
-    client, host_path = get_transport_and_path(remote)
+    config = StackedConfig.default()
+    client, host_path = get_transport_and_path(remote, config=config)
     return client.get_refs(host_path)