[PR] #87 from RealFX-Code: Windows git command check

This commit is contained in:
Hykilpikonna 2023-02-07 18:18:33 -05:00 committed by GitHub
commit b9eeb068fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

15
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "hyfetch",
"justMyCode": true
}
]
}

View file

@ -7,6 +7,7 @@ import shlex
import subprocess import subprocess
import sys import sys
import zipfile import zipfile
import shutil
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from subprocess import check_output from subprocess import check_output
@ -150,7 +151,6 @@ def get_command_path() -> str:
return cmd_path return cmd_path
def ensure_git_bash() -> Path: def ensure_git_bash() -> Path:
""" """
Ensure git bash installation for windows Ensure git bash installation for windows
@ -163,6 +163,17 @@ def ensure_git_bash() -> Path:
if def_path.is_file(): if def_path.is_file():
return def_path return def_path
# Labda expression that finds out if a command exists
cmd_exists = lambda x: shutil.which(x) is not None
# TEMP-FIX: Make git not hard-coded to being installed "officially" via the git-for-windows installer
if ( cmd_exists("git.exe") ):
pth = Path(shutil.which("git")).parent
if(os.path.isfile(pth / r'bash.exe')):
return pth / r'bash.exe'
elif ( os.path.isfile(pth / r'/bin/bash.exe')):
return pth / r'/bin/bash.exe'
# Find installation in PATH (C:\Program Files\Git\cmd should be in path) # Find installation in PATH (C:\Program Files\Git\cmd should be in path)
pth = (os.environ.get('PATH') or '').lower().split(';') pth = (os.environ.get('PATH') or '').lower().split(';')
pth = [p for p in pth if p.endswith(r'\git\cmd')] pth = [p for p in pth if p.endswith(r'\git\cmd')]