changeset 7886:df275f701d53

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 ...
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 11 Sep 2019 23:00:57 +0200
parents 7feb2281a8b0
children ae155f6a99ad
files kallithea/lib/utils.py
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/utils.py	Wed Sep 11 23:00:53 2019 +0200
+++ b/kallithea/lib/utils.py	Wed Sep 11 23:00:57 2019 +0200
@@ -29,6 +29,7 @@
 import logging
 import os
 import re
+import sys
 import traceback
 from distutils.version import StrictVersion
 
@@ -581,7 +582,7 @@
 
 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 @@
     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 @@
         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',