Skip to content

utf8 codec error when format_patch generates unicode #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kirotawa opened this issue Apr 15, 2015 · 2 comments
Closed

utf8 codec error when format_patch generates unicode #281

kirotawa opened this issue Apr 15, 2015 · 2 comments

Comments

@kirotawa
Copy link

How to reproduce:
git.format_patch(-1, sha, '--stdout')

A sample of patch generated that raise this issue:

From 74ef1e8b937d9693f9aba4579271266bb778c935 Mon Sep 17 00:00:00 2001
From: 
Date: Wed, 15 Apr 2015 02:43:35 -0300
Subject: [PATCH] bla

---
 test3 | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 test3

diff --git a/test3 b/test3
new file mode 100644
index 0000000..d7659a0
--- /dev/null
+++ b/test3
@@ -0,0 +1,2 @@
++      [Ulf M<f6>ller]
++ 
-- 
1.9.1

the offender is and are raising :

In [31]: g.format_patch(-1, sha, '--stdout')
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-31-0a8d764befbc> in <module>()
----> 1 g.format_patch(-1, sha, '--stdout')

/usr/local/lib/python2.7/dist-packages/GitPython-0.3.6-py2.7.egg/git/cmd.pyc in <lambda>(*args, **kwargs)
    429         if name[0] == '_':
    430             return LazyMixin.__getattr__(self, name)
--> 431         return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
    432 
    433     def _set_cache_(self, attr):

/usr/local/lib/python2.7/dist-packages/GitPython-0.3.6-py2.7.egg/git/cmd.pyc in _call_process(self, method, *args, **kwargs)
    812             # END provide better error message
    813         else:
--> 814             return self.execute(make_call(), **_kwargs)
    815         # END handle windows default installation
    816 

/usr/local/lib/python2.7/dist-packages/GitPython-0.3.6-py2.7.egg/git/cmd.pyc in execute(self, command, istream, with_keep_cwd, with_extended_output, with_exceptions, as_process, output_stream, stdout_as_string, **subprocess_kwargs)
    608 
    609         if isinstance(stdout_value, bytes) and stdout_as_string:  # could also be output_stream
--> 610             stdout_value = stdout_value.decode(defenc)
    611 
    612         # Allow access to the command's status code

/usr/lib/python2.7/encodings/utf_8.pyc in decode(input, errors)
     14 
     15 def decode(input, errors='strict'):
---> 16     return codecs.utf_8_decode(input, errors, True)
     17 
     18 class IncrementalEncoder(codecs.IncrementalEncoder):

UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 372: invalid start byte
@Byron
Copy link
Member

Byron commented Apr 15, 2015

If you execute g.format_patch(-1, sha, '--stdout', stdout_as_string=False), you will receive plain bytes without GitPython trying to decode it as UTF-8.
Please close this issue if it works for you.
Thanks

@kirotawa
Copy link
Author

Thank you, it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants