diff --git a/build/git_revision.py b/build/git_revision.py index d84886d8b8427..0b0653f3ad3f9 100755 --- a/build/git_revision.py +++ b/build/git_revision.py @@ -10,11 +10,7 @@ import subprocess import os import argparse - - -def is_windows(): - os_id = sys.platform - return os_id.startswith('win32') or os_id.startswith('cygwin') +from shutil import which # Natively supported since python 3.3 def get_repository_version(repository): @@ -22,9 +18,12 @@ def get_repository_version(repository): if not os.path.exists(repository): raise IOError('path does not exist') - git = 'git' - if is_windows(): - git = 'git.bat' + git_candidates = ['git', 'git.sh', 'git.bat'] + git = next(filter(which, git_candidates), None) + if git is None: + candidates = "', '".join(git_candidates) + raise IOError(f"Looks like GIT is not on the path. Tried '{candidates}'") + version = subprocess.check_output([ git, '-C', diff --git a/tools/githooks/setup.py b/tools/githooks/setup.py index ea8edf467a838..9e677e96b91d5 100755 --- a/tools/githooks/setup.py +++ b/tools/githooks/setup.py @@ -10,6 +10,7 @@ import os import subprocess import sys +from shutil import which # Natively supported since python 3.3 SRC_ROOT = os.path.dirname( os.path.dirname( @@ -19,17 +20,13 @@ FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter') -def IsWindows(): - os_id = sys.platform - return os_id.startswith('win32') or os_id.startswith('cygwin') - - def Main(argv): - git = 'git' githooks = os.path.join(FLUTTER_DIR, 'tools', 'githooks') - if IsWindows(): - git = 'git.bat' - githooks = os.path.join(githooks, 'windows') + git_candidates = ['git', 'git.sh', 'git.bat'] + git = next(filter(which, git_candidates), None) + if git is None: + candidates = "', '".join(git_candidates) + raise IOError(f"Looks like GIT is not on the path. Tried '{candidates}'") result = subprocess.run([ git, 'config',