Skip to content
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

When 32-bit Git is installed on 64-bit Windows, fails to launch editor #125

Open
nyanpasu64 opened this issue May 24, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@nyanpasu64
Copy link

I accidentally installed 32-bit Git on 64-bit Windows, so Git ended up in C:\Program Files (x86)\Git.

On Windows, git-revise launches the editor in a sh.exe -ec exec ... environment. The path to sh.exe is calculated in sh_path():

def sh_path() -> str:
if os.name == "nt":
# On Windows, git is installed using Git for Windows, which installs
# into the "Git" directory in "%ProgramFiles%". Use the `sh.exe` file
# from that directory to perform shell operations, so they're executed
# in the expected environment.
return os.path.join(os.environ["PROGRAMFILES"], "Git", "bin", "sh.exe")
return "/bin/sh"

Unfortunately os.environ["PROGRAMFILES"] is C:\Program Files even though Git is located in C:\Program Files (x86). As a result, running an editor fails:

Traceback (most recent call last):
  File "C:\Users\nyanpasu64\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\nyanpasu64\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\users\nyanpasu64\.local\bin\git-revise.exe\__main__.py", line 7, in <module>
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\tui.py", line 263, in main
    inner_main(args, repo)
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\tui.py", line 254, in inner_main
    interactive(args, repo, staged, head)
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\tui.py", line 137, in interactive
    todos = edit_todos(repo, todos, msgedit=args.edit)
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\todo.py", line 208, in edit_todos
    response = run_sequence_editor(
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\utils.py", line 202, in run_sequence_editor
    return run_specific_editor(
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\utils.py", line 142, in run_specific_editor
    data = edit_file_with_editor(editor, path)
  File "C:\Users\nyanpasu64\.local\pipx\venvs\git-revise\lib\site-packages\gitrevise\utils.py", line 66, in edit_file_with_editor
    run(cmd, check=True, cwd=path.parent)
  File "C:\Users\nyanpasu64\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\nyanpasu64\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\nyanpasu64\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1311, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

Is there a better way to auto-detect the correct Git path?

@mystor mystor added the enhancement New feature or request label May 27, 2022
@mystor
Copy link
Owner

mystor commented May 27, 2022

As far as I know, there's no reliable way to find it on windows other than looking in specific directories one at a time, checking if they exist. We could perhaps consider having a priority list of program files paths to check in rather than using a single callback, perhaps checking PROGRAMFILES, PROGRAMFILES(X86), PROGRAMW6432 in that order (if they're defined) would make sense? (based on https://en.wikipedia.org/wiki/Environment_variable#ProgramFiles). That way it should handle any combination of 32/64-bit python3 install and 32/64-bit git install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants