# HG changeset patch # User Mads Kiilerich # Date 2019-09-11 23:00:57 # Node ID df275f701d5374a9a0c34fed140f0aeb3f04b3c6 # Parent 7feb2281a8b0308e081a817d4ef3b2cbf42105b6 git: exit early if Git is found but too old (Issue #342) The warning in the logs were too easy to miss. It is still OK if git isn't found at all... for example if git_path configuration doesn't point at something that looks like git. The git_path configuration already had no default, so just make the code path for that case more clean. (An easy next/alternative step could be to remove git from BACKENDS if it isn't configured ...) The system exit is similar to what is done in 0e33880b2897 ... even though exiting from from a library might be a bit worse ... diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -29,6 +29,7 @@ import datetime import logging import os import re +import sys import traceback from distutils.version import StrictVersion @@ -581,7 +582,7 @@ git_req_ver = StrictVersion('1.7.4') def check_git_version(): """ - Checks what version of git is installed in system, and issues a warning + Checks what version of git is installed on the system, and raise a system exit if it's too old for Kallithea to work properly. """ from kallithea import BACKENDS @@ -591,6 +592,10 @@ def check_git_version(): if 'git' not in BACKENDS: return None + if not settings.GIT_EXECUTABLE_PATH: + log.warning('No git executable configured - check "git_path" in the ini file.') + return None + stdout, stderr = GitRepository._run_git_command(['--version'], _bare=True, _safe=True) @@ -603,10 +608,14 @@ def check_git_version(): log.debug('Git executable: "%s", version %s (parsed from: "%s")', settings.GIT_EXECUTABLE_PATH, ver, stdout.strip()) if ver < git_req_ver: - log.warning('Kallithea detected %s version %s, which is too old ' - 'for the system to function properly. ' - 'Please upgrade to version %s or later.', - settings.GIT_EXECUTABLE_PATH, ver, git_req_ver) + log.error('Kallithea detected %s version %s, which is too old ' + 'for the system to function properly. ' + 'Please upgrade to version %s or later. ' + 'If you strictly need Mercurial repositories, you can ' + 'clear the "git_path" setting in the ini file.', + settings.GIT_EXECUTABLE_PATH, ver, git_req_ver) + log.error("Terminating ...") + sys.exit(1) else: ver = StrictVersion('0.0.0') log.warning('Error finding version number in "%s --version" stdout: %r',