浏览代码

Fix dulwich.porcelain.pull() with Python3. (#451)

Jelmer Vernooij 8 年之前
父节点
当前提交
aaaa6894e9
共有 4 个文件被更改,包括 37 次插入18 次删除
  1. 2 0
      NEWS
  2. 8 5
      dulwich/porcelain.py
  3. 1 1
      dulwich/tests/test_objects.py
  4. 26 12
      dulwich/tests/test_porcelain.py

+ 2 - 0
NEWS

@@ -5,6 +5,8 @@
   * Allow missing trailing LF when reading service name from
     HTTP servers. (Jelmer Vernooij, Andrew Shadura, #442)
 
+  * Fix dulwich.porcelain.pull() on Python3. (Jelmer Vernooij, #451)
+
  CHANGES
 
   * Changed license from "GNU General Public License, version 2.0 or later"

+ 8 - 5
dulwich/porcelain.py

@@ -139,8 +139,8 @@ def open_repo_closing(path_or_repo):
     return closing(Repo(path_or_repo))
 
 
-def archive(repo, committish=None, outstream=sys.stdout,
-            errstream=sys.stderr):
+def archive(repo, committish=None, outstream=default_bytes_out_stream,
+            errstream=default_bytes_err_stream):
     """Create an archive.
 
     :param repo: Path of repository for which to generate an archive.
@@ -564,7 +564,7 @@ def reset(repo, mode, committish="HEAD"):
 
 
 def push(repo, remote_location, refspecs=None,
-         outstream=sys.stdout, errstream=sys.stderr):
+         outstream=default_bytes_out_stream, errstream=default_bytes_err_stream):
     """Remote push with dulwich via dulwich.client
 
     :param repo: Path to repository
@@ -607,7 +607,7 @@ def push(repo, remote_location, refspecs=None,
 
 
 def pull(repo, remote_location, refspecs=None,
-         outstream=sys.stdout, errstream=sys.stderr):
+         outstream=default_bytes_out_stream, errstream=default_bytes_err_stream):
     """Pull from remote via dulwich.client
 
     :param repo: Path to repository
@@ -618,6 +618,8 @@ def pull(repo, remote_location, refspecs=None,
     """
     # Open the repo
     with open_repo_closing(repo) as r:
+        if refspecs is None:
+            refspecs = [b"HEAD"]
         selected_refs = []
         def determine_wants(remote_refs):
             selected_refs.extend(parse_reftuples(remote_refs, r.refs, refspecs))
@@ -816,7 +818,8 @@ def branch_list(repo):
         return r.refs.keys(base=b"refs/heads/")
 
 
-def fetch(repo, remote_location, outstream=sys.stdout, errstream=sys.stderr):
+def fetch(repo, remote_location, outstream=sys.stdout,
+        errstream=default_bytes_err_stream):
     """Fetch objects from a remote server.
 
     :param repo: Path to the repository

+ 1 - 1
dulwich/tests/test_objects.py

@@ -1136,7 +1136,7 @@ class ShaFileSerializeTests(TestCase):
 class PrettyFormatTreeEntryTests(TestCase):
 
     def test_format(self):
-        self.assertEquals(
+        self.assertEqual(
                 '40000 tree 40820c38cfb182ce6c8b261555410d8382a5918b\tfoo\n',
                 pretty_format_tree_entry(b"foo", 0o40000,
                     b"40820c38cfb182ce6c8b261555410d8382a5918b"))

+ 26 - 12
dulwich/tests/test_porcelain.py

@@ -532,10 +532,8 @@ class PushTests(PorcelainTestCase):
 
 class PullTests(PorcelainTestCase):
 
-    def test_simple(self):
-        outstream = BytesIO()
-        errstream = BytesIO()
-
+    def setUp(self):
+        super(PullTests, self).setUp()
         # create a file for initial commit
         handle, fullpath = tempfile.mkstemp(dir=self.repo.path)
         os.close(handle)
@@ -545,10 +543,10 @@ class PullTests(PorcelainTestCase):
                          author=b'test', committer=b'test')
 
         # Setup target repo
-        target_path = tempfile.mkdtemp()
-        self.addCleanup(shutil.rmtree, target_path)
-        target_repo = porcelain.clone(self.repo.path, target=target_path,
-                                      errstream=errstream)
+        self.target_path = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, self.target_path)
+        target_repo = porcelain.clone(self.repo.path, target=self.target_path,
+                errstream=BytesIO())
         target_repo.close()
 
         # create a second file to be pushed
@@ -562,12 +560,28 @@ class PullTests(PorcelainTestCase):
         self.assertTrue(b'refs/heads/master' in self.repo.refs)
         self.assertTrue(b'refs/heads/master' in target_repo.refs)
 
+    def test_simple(self):
+        outstream = BytesIO()
+        errstream = BytesIO()
+
         # Pull changes into the cloned repo
-        porcelain.pull(target_path, self.repo.path, b'refs/heads/master',
+        porcelain.pull(self.target_path, self.repo.path, b'refs/heads/master',
             outstream=outstream, errstream=errstream)
 
         # Check the target repo for pushed changes
-        with closing(Repo(target_path)) as r:
+        with closing(Repo(self.target_path)) as r:
+            self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
+
+    def test_no_refspec(self):
+        outstream = BytesIO()
+        errstream = BytesIO()
+
+        # Pull changes into the cloned repo
+        porcelain.pull(self.target_path, self.repo.path, outstream=outstream,
+                       errstream=errstream)
+
+        # Check the target repo for pushed changes
+        with closing(Repo(self.target_path)) as r:
             self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
 
 
@@ -812,7 +826,7 @@ class LsTreeTests(PorcelainTestCase):
 
         f = StringIO()
         porcelain.ls_tree(self.repo, b"HEAD", outstream=f)
-        self.assertEquals(f.getvalue(), "")
+        self.assertEqual(f.getvalue(), "")
 
     def test_simple(self):
         # Commit a dummy file then modify it
@@ -826,6 +840,6 @@ class LsTreeTests(PorcelainTestCase):
 
         f = StringIO()
         porcelain.ls_tree(self.repo, b"HEAD", outstream=f)
-        self.assertEquals(
+        self.assertEqual(
                 f.getvalue(),
                 '100644 blob 8b82634d7eae019850bb883f06abf428c58bc9aa\tfoo\n')