benthayer / git-gud

Wanna git gud? Then get git-gud, and git gud at git!
MIT License
401 stars 42 forks source link

git gud levels breaks on Windows #338

Open sahansk2 opened 3 years ago

sahansk2 commented 3 years ago
Sahan Kumarasinghe@DESKTOP-NTS61AN MINGW64 ~/my-git-gud (master)
$ git gud levels
Traceback (most recent call last):
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Sahan Kumarasinghe\AppData\Local\Programs\Python\Python39\Scripts\git-gud.exe\__main__.py", line 7, in <module>
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\site-packages\gitgud\__main__.py", line 530, in main
    GitGud().parse()
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\site-packages\gitgud\__main__.py", line 524, in parse
    self.command_dict[args.command](args)
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\site-packages\gitgud\__main__.py", line 378, in handle_levels
    show_skill_tree(
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\site-packages\gitgud\user_messages\__init__.py", line 202, in show_skill_tree
    display_entry(
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\site-packages\gitgud\user_messages\__init__.py", line 170, in display_entry
    print(indent + format_string.format(
  File "c:\users\sahan kumarasinghe\appdata\local\programs\python\python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to <undefined>
Levels in the current skill "intro" :

0. Introduction (intro)

This breaks on Git Gud versions 0.3.1 and 0.4.0. Just installed git gud and git bash. Looks like it's got something to do with the elbow characters. I'll open a PR soon for a quick fix.

sahansk2 commented 3 years ago

I redact my statement. It's got something to do with how Python interacts with Git Bash's console. A quick fix would be to use winpty and add an alias to the ~/.bashrc:

echo "alias git-gud='winpty git gud'" >> ~/.bashrc

I won't open a PR for this, since it's not only git gud levels that's broken, but also any Git command called by Git Gud that needs color. That, and a bunch of other random stuff. This whole situation actually might also explain #44 as well.