Upon install of stgit in a virtualenv in Windows, running stg show (or any command) throws the following error:
Error: Unhandled exception:
Traceback (most recent call last):
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\main.py", line 188, in _main
ret = command.func(parser, options, args)
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\commands\series.py", line 194, in func
stack = directory.repository.get_stack(options.branch)
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\lib\stack.py", line 428, in get_stack
name = self.current_branch_name
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\lib\git\repository.py", line 223, in current_branch_name
return utils.strip_prefix('refs/heads/', self.head_ref)
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\lib\git\repository.py", line 311, in head_ref
return self.run(['git', 'symbolic-ref', '-q', 'HEAD']).output_one_line()
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\run.py", line 254, in output_one_line
outlines = self.output_lines(sep)
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\run.py", line 245, in output_lines
outdata = self._run_io()
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\run.py", line 133, in _run_io
p = subprocess.Popen(
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
TypeError: environment can only contain strings
It can be quick-fixed on my system by replacing
| def _prep_env(self): |
with the following:
def _prep_env(self): return self._env
My understanding, also from reading this comment (https://bugzilla.mozilla.org/show_bug.cgi?id=1585258#c4)
is, that this is a relict from Python2, and as Stgit supports Python >=3.5, that the opposite of fsencode_utf8 is required, fsdecode_utf8. On Linux, both strings and bytes are accepted, but Windows needs the env to be strings.
Stgit version: master ( c01b32a )
Python version: 3.8.3
OS: Windows 10-msys2