Selaa lähdekoodia

Add remote in dulwich.porcelain.clone.

Jelmer Vernooij 8 vuotta sitten
vanhempi
commit
8cf1640314
6 muutettua tiedostoa jossa 37 lisäystä ja 0 poistoa
  1. 2 0
      NEWS
  2. 4 0
      dulwich/config.py
  3. 7 0
      dulwich/porcelain.py
  4. 8 0
      dulwich/repo.py
  5. 8 0
      dulwich/tests/test_porcelain.py
  6. 8 0
      dulwich/tests/test_repository.py

+ 2 - 0
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

+ 4 - 0
dulwich/config.py

@@ -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):

+ 7 - 0
dulwich/porcelain.py

@@ -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()

+ 8 - 0
dulwich/repo.py

@@ -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')

+ 8 - 0
dulwich/tests/test_porcelain.py

@@ -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')

+ 8 - 0
dulwich/tests/test_repository.py

@@ -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()