Prechádzať zdrojové kódy

Add tests / improvements for push output.

Jelmer Vernooij 4 rokov pred
rodič
commit
c2263144d3
2 zmenil súbory, kde vykonal 22 pridanie a 6 odobranie
  1. 8 6
      dulwich/porcelain.py
  2. 14 0
      dulwich/tests/test_porcelain.py

+ 8 - 6
dulwich/porcelain.py

@@ -976,26 +976,28 @@ def push(repo, remote_location=None, refspecs=None,
             return new_refs
 
         err_encoding = getattr(errstream, 'encoding', None) or DEFAULT_ENCODING
-        remote_location_bytes = client.get_url(path).encode(err_encoding)
+        remote_location = client.get_url(path)
         try:
             result = client.send_pack(
                 path, update_refs,
                 generate_pack_data=r.generate_pack_data,
                 progress=errstream.write)
-            errstream.write(
-                b"Push to " + remote_location_bytes + b" successful.\n")
         except SendPackError as e:
             raise Error(
-                "Push to " + remote_location_bytes +
+                "Push to " + remote_location +
                 " failed -> " + e.args[0].decode(), inner=e)
+        else:
+            errstream.write(
+                b"Push to " +
+                remote_location.encode(err_encoding) + b" successful.\n")
 
         for ref, error in (result.ref_status or {}).items():
             if error is not None:
                 errstream.write(
-                    b"Push of ref %s failed: %s" %
+                    b"Push of ref %s failed: %s\n" %
                     (ref, error.encode(err_encoding)))
             else:
-                errstream.write(b'Ref %s updated' % ref)
+                errstream.write(b'Ref %s updated\n' % ref)
 
         if remote_name is not None:
             _import_remote_refs(r.refs, remote_name, remote_changed_refs)

+ 14 - 0
dulwich/tests/test_porcelain.py

@@ -22,6 +22,7 @@
 
 from io import BytesIO, StringIO
 import os
+import re
 import shutil
 import tarfile
 import tempfile
@@ -981,6 +982,9 @@ class PushTests(PorcelainTestCase):
             author=b'author <email>',
             committer=b'committer <email>')
 
+        outstream = BytesIO()
+        errstream = BytesIO()
+
         # Push to the remote
         self.assertRaises(
             porcelain.DivergedBranches,
@@ -992,6 +996,12 @@ class PushTests(PorcelainTestCase):
             b'refs/heads/master': remote_id,
             }, self.repo.get_refs())
 
+        self.assertEqual(b'', outstream.getvalue())
+        self.assertEqual(b'', errstream.getvalue())
+
+        outstream = BytesIO()
+        errstream = BytesIO()
+
         # Push to the remote with --force
         porcelain.push(
             clone_path, self.repo.path, b'refs/heads/master',
@@ -1002,6 +1012,10 @@ class PushTests(PorcelainTestCase):
             b'refs/heads/master': local_id,
             }, self.repo.get_refs())
 
+        self.assertEqual(b'', outstream.getvalue())
+        self.assertTrue(
+            re.match(b'Push to .* successful.\n', errstream.getvalue()))
+
 
 class PullTests(PorcelainTestCase):