GitPython
GitPython copied to clipboard
Use winreg to find GIT_PYTHON_GIT_EXECUTABLE
As per https://stackoverflow.com/questions/8507368/programmatically-not-manually-finding-the-path-where-git-is-installed-on-a-win
It looks like one could use the winreg in order to find git executable. Is this something you tried or are willing to take patch?
FWIW, the following method do works for me:
import sys
if sys.platform == 'win32':
import os
import winreg
def get_git_binary_path():
proc_arch = os.getenv('PROCESSOR_ARCHITECTURE', '').lower()
proc_arch64 = os.getenv('PROCESSOR_ARCHITEW6432','').lower()
if proc_arch == 'x86' and not proc_arch64:
arch_keys = {0}
elif proc_arch == 'x86' or proc_arch == 'amd64':
arch_keys = {winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY}
else:
raise Exception("Unhandled arch: %s" % proc_arch)
for arch_key in arch_keys:
for base_key in [winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER]:
try:
with winreg.OpenKey(
base_key, r"Software\GitForWindows",
0, winreg.KEY_READ | arch_key) as key:
path = winreg.QueryValueEx(key, 'InstallPath')[0]
git_path = os.path.join(path, 'bin', 'git.exe')
if os.path.exists(git_path):
return git_path
except FileNotFoundError:
continue
return None
else:
# on normal platforms, git is just in the PATH
def get_git_binary_path():
return 'git'
@tardyp thanks a lot for the suggestion and the research! If you could provide the code above in a PR I would happily merge it.