From 526abd92516802e082b89e075ed0f3102e5717f3 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 26 Nov 2016 14:42:29 -0800 Subject: [PATCH] Warn on cygwin python/git mismatch. Resolves #354 --- pre_commit/git.py | 24 ++++++++++++++++++++++++ pre_commit/main.py | 1 + 2 files changed, 25 insertions(+) diff --git a/pre_commit/git.py b/pre_commit/git.py index 96e7390d..ab980181 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -4,6 +4,7 @@ import functools import logging import os.path import re +import sys from pre_commit.errors import FatalError from pre_commit.util import CalledProcessError @@ -102,3 +103,26 @@ def get_files_matching(all_file_list_strategy): get_staged_files_matching = get_files_matching(get_staged_files) get_all_files_matching = get_files_matching(get_all_files) get_conflicted_files_matching = get_files_matching(get_conflicted_files) + + +def check_for_cygwin_mismatch(): + """See https://github.com/pre-commit/pre-commit/issues/354""" + if sys.platform in ('cygwin', 'win32'): # pragma: no cover (windows) + is_cygwin_python = sys.platform == 'cygwin' + toplevel = cmd_output('git', 'rev-parse', '--show-toplevel')[1] + is_cygwin_git = toplevel.startswith('/') + + if is_cygwin_python ^ is_cygwin_git: + exe_type = {True: '(cygwin)', False: '(windows)'} + logger.warn( + 'pre-commit has detected a mix of cygwin python / git\n' + 'This combination is not supported, it is likely you will ' + 'receive an error later in the program.\n' + 'Make sure to use cygwin git+python while using cygwin\n' + 'These can be installed through the cygwin installer.\n' + ' - python {}\n' + ' - git {}\n'.format( + exe_type[is_cygwin_python], + exe_type[is_cygwin_git], + ) + ) diff --git a/pre_commit/main.py b/pre_commit/main.py index 97281890..4bcd153b 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -152,6 +152,7 @@ def main(argv=None): with error_handler(): add_logging_handler(args.color) + git.check_for_cygwin_mismatch() runner = Runner.create() if args.command == 'install':