Add remote in dulwich.porcelain.clone.
authorJelmer Vernooij <jelmer@jelmer.uk>
Wed, 28 Dec 2016 16:36:44 +0000 (16:36 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Wed, 28 Dec 2016 16:36:44 +0000 (16:36 +0000)
NEWS
dulwich/config.py
dulwich/porcelain.py
dulwich/repo.py
dulwich/tests/test_porcelain.py
dulwich/tests/test_repository.py

diff --git a/NEWS b/NEWS
index 03af6a0adf5649ef80becfd92fdd0786694a78d8..9b0db1b272dfe4c77744741684054297ba3cbb02 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@
   * Allow both unicode and byte strings for host paths
     in dulwich.client. (#435, Jelmer Vernooij)
 
+  * Add remote from porcelain.clone. (#466, Jelmer Vernooij)
+
 0.16.1 2016-12-25
 
  BUG FIXES
index 25869a98d3fad63a5713cc50dac22e502b8541b0..93c8d84d5c1795eb673807bb163e0e01273cd9d4 100644 (file)
@@ -149,6 +149,10 @@ class ConfigDict(Config, MutableMapping):
     def set(self, section, name, value):
         if not isinstance(section, tuple):
             section = (section, )
+        if not isinstance(name, bytes):
+            raise TypeError(name)
+        if type(value) not in (bool, bytes):
+            raise TypeError(value)
         self._values.setdefault(section, OrderedDict())[name] = value
 
     def iteritems(self, section):
index cab02ed6c224207a9a128af524ccb3a2ac551e0c..32e7ce2937dc46bd5198689c386c27a5dbaf2727 100644 (file)
@@ -282,6 +282,13 @@ def clone(source, target=None, bare=False, checkout=None,
                 if n.startswith(b'refs/tags/') and
                 not n.endswith(ANNOTATED_TAG_SUFFIX)})
         r[b"HEAD"] = remote_refs[b"HEAD"]
+        target_config = r.get_config()
+        if not isinstance(source, bytes):
+            source = source.encode(DEFAULT_ENCODING)
+        target_config.set((b'remote', b'origin'), b'url', source)
+        target_config.set((b'remote', b'origin'), b'fetch',
+            b'+refs/heads/*:refs/remotes/origin/*')
+        target_config.write_to_path()
         if checkout:
             errstream.write(b'Checking out HEAD\n')
             r.reset_index()
index 06e833aea187375002536b201645ff59fc633a13..ca3620ea400dd14c0d40785163eb3b1bcb1a154c 100644 (file)
@@ -858,6 +858,14 @@ class Repo(BaseRepo):
             target.refs.add_if_new(DEFAULT_REF, self.refs[DEFAULT_REF])
         except KeyError:
             pass
+        target_config = target.get_config()
+        encoded_path = self.path
+        if not isinstance(encoded_path, bytes):
+            encoded_path = encoded_path.encode(sys.getfilesystemencoding())
+        target_config.set((b'remote', b'origin'), b'url', encoded_path)
+        target_config.set((b'remote', b'origin'), b'fetch',
+            b'+refs/heads/*:refs/remotes/origin/*')
+        target_config.write_to_path()
 
         # Update target head
         head_chain, head_sha = self.refs.follow(b'HEAD')
index 4de06626087fdb34e2a8b836c4e5d7c7b8573fb2..45b1c4a05719b74f081a3e78acad8580ff72987d 100644 (file)
@@ -126,6 +126,14 @@ class CloneTests(PorcelainTestCase):
         self.assertEqual(c3.id, target_repo.refs[b'refs/tags/foo'])
         self.assertTrue(b'f1' not in os.listdir(target_path))
         self.assertTrue(b'f2' not in os.listdir(target_path))
+        c = r.get_config()
+        encoded_path = self.repo.path
+        if not isinstance(encoded_path, bytes):
+            encoded_path = encoded_path.encode('utf-8')
+        self.assertEqual(encoded_path, c.get((b'remote', b'origin'), b'url'))
+        self.assertEqual(
+            b'+refs/heads/*:refs/remotes/origin/*',
+            c.get((b'remote', b'origin'), b'fetch'))
 
     def test_simple_local_with_checkout(self):
         f1_1 = make_object(Blob, data=b'f1')
index 4c4040dab439f30907b86e7e43de51b74963d68e..02e0387cc9dc8b21714355f23f11917aad4b808c 100644 (file)
@@ -246,6 +246,14 @@ class RepositoryRootTests(TestCase):
             shas = [e.commit.id for e in r.get_walker()]
             self.assertEqual(shas, [t.head(),
                              b'2a72d929692c41d8554c07f6301757ba18a65d91'])
+            c = t.get_config()
+            encoded_path = r.path
+            if not isinstance(encoded_path, bytes):
+                encoded_path = encoded_path.encode(sys.getfilesystemencoding())
+            self.assertEqual(encoded_path, c.get((b'remote', b'origin'), b'url'))
+            self.assertEqual(
+                b'+refs/heads/*:refs/remotes/origin/*',
+                c.get((b'remote', b'origin'), b'fetch'))
 
     def test_clone_no_head(self):
         temp_dir = self.mkdtemp()