Skip to content

Fix universal_newlines TypeError - #1098

Merged
Byron merged 1 commit into
gitpython-developers:masterfrom
wisnij:jwisniewski/20201230-universal-newlines
Dec 31, 2020
Merged

Fix universal_newlines TypeError#1098
Byron merged 1 commit into
gitpython-developers:masterfrom
wisnij:jwisniewski/20201230-universal-newlines

Conversation

@wisnij

Copy link
Copy Markdown

Currently, using git.cmd.Git with universal_newlines=True throws a TypeError:

In [1]: import git
In [2]: git.__version__
Out[2]: '3.1.7'
In [3]: g = git.cmd.Git()
In [4]: g.ls_files(universal_newlines=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-dc77db814df8> in <module>
----> 1 g.ls_files(universal_newlines=True)
~/venv/lib/python3.6/site-packages/git/cmd.py in <lambda>(*args, **kwargs)
540 if name[0] == '_':
541 return LazyMixin.__getattr__(self, name)
--> 542 return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
543
544 def set_persistent_git_options(self, **kwargs):
~/venv/lib/python3.6/site-packages/git/cmd.py in _call_process(self, method, *args, **kwargs)
1003 call.extend(args)
1004
-> 1005 return self.execute(call, **exec_kwargs)
1006
1007 def _parse_object_header(self, header_line):
~/venv/lib/python3.6/site-packages/git/cmd.py in execute(self, command, istream, with_extended_output, with_exceptions, as_process, output_stream, stdout_as_string, kill_after_timeout, with_stdout, universal_newlines, shell, env, max_chunk_size, **subprocess_kwargs)
784 'secs.' % (" ".join(command), kill_after_timeout)).encode(defenc)
785 # strip trailing "\n"
--> 786 if stdout_value.endswith(b"\n"):
787 stdout_value = stdout_value[:-1]
788 if stderr_value.endswith(b"\n"):
TypeError: endswith first arg must be str or a tuple of str, not bytes

I wasn't able to try out an automated test case due to #1090, but it doesn't throw an error anymore when I test it out manually:

~/code/GitPython (jwisniewski/20201230-universal-newlines) $ python
Python 3.6.5 (default, Sep 29 2020, 16:04:29)
[GCC Apple LLVM 12.0.0 (clang-1200.0.31.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> g = git.cmd.Git()
>>> g.ls_files(universal_newlines=True)
'.appveyor.yml\n.codeclimate.yml\n.coveragerc\n.deepsource.toml\n[...]'

@Byron
Byron merged commit 696e4ed into gitpython-developers:masterDec 31, 2020
@ByronByron added this to the v3.1.12 - Bugfixes milestone Dec 31, 2020
@Byron

Copy link
Copy Markdown
Member

Thanks a lot! It looks like this fix was long overdue!

@EliahKagan

Copy link
Copy Markdown
Member

This appears to have fixed #661.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@wisnij@Byron@EliahKagan