GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

Error using Chinese path or Chinese branch name

Open xunmi-git opened this issue 4 years ago • 2 comments

Environmental Information

Windows10 Python3.8 GitPython 3.1.24

Error 1

Chinese path:

git.Repo.clone_from(url="[email protected]:xun-mi-git/test-x.git", to_path="C:\\Users\\asus\\3D Objects\\个人项目\\test")

Error message

Exception in thread Thread-6:
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1370, in _readerthread
    buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 41: illegal multibyte sequence

screenshot

寻觅_20210619020652

Error 2

Chinese branch:

    git.Repo.clone_from(url="[email protected]:xun-mi-git/test-x.git", to_path="C:\\test")
    a = Repo("C:\\test").remotes[0]
    for i in a.refs:
        print(i.name)
    a = a.pull()

Error message

origin/HEAD
origin/默认分支
Exception in thread Thread-7:
Traceback (most recent call last):
  File "C:\Users\asus\3D Objects\Python环境\常用通用库\lib\site-packages\git\cmd.py", line 109, in pump_stream
    for line in stream:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 58: illegal multibyte sequence

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\asus\3D Objects\Python环境\常用通用库\lib\site-packages\git\cmd.py", line 122, in pump_stream
    raise CommandError([f'<{name}-pump>'] + remove_password_if_present(cmdline), ex) from ex
git.exc.CommandError: Cmd('<stderr-pump>') failed due to: UnicodeDecodeError(''gbk' codec can't decode byte 0xae in position 58: illegal multibyte sequence')
  cmdline: <stderr-pump> git pull -v origin

screenshot

寻觅_20213119023148

xunmi-git avatar Oct 19 '21 06:10 xunmi-git

Use if required:[email protected]:xun-mi-git/test-x.gitThis library test

xunmi-git avatar Oct 19 '21 06:10 xunmi-git

Thanks for this wonderful issue! I am sorry to say that dealing with encodings is a mess in GitPython. The examples above seem to indicate that it tries to see things as strings but doesn't get their encoding right. Probably it should just use UTF-8 instead of gbk.

Maybe as a workaround, the default encoding of the python interpreter can be set to utf-8.

Byron avatar Oct 20 '21 00:10 Byron