changeset 2890:84414d73c233 beta

Add git version detection to warn users that Git used in system is to old. ref #588 - also show git version in system details in settings page
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 02 Oct 2012 21:32:00 +0200
parents 7d494079f366
children 9812e617c564
files rhodecode/config/environment.py rhodecode/controllers/admin/settings.py rhodecode/lib/utils.py
diffstat 3 files changed, 42 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/environment.py	Tue Oct 02 20:15:07 2012 +0200
+++ b/rhodecode/config/environment.py	Tue Oct 02 21:32:00 2012 +0200
@@ -18,7 +18,7 @@
 from rhodecode.lib import helpers
 from rhodecode.lib.auth import set_available_permissions
 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config,\
-    load_rcextensions
+    load_rcextensions, check_git_version
 from rhodecode.lib.utils2 import engine_from_config, str2bool
 from rhodecode.model import init_model
 from rhodecode.model.scm import ScmModel
@@ -86,6 +86,9 @@
         if not int(os.environ.get('RC_WHOOSH_TEST_DISABLE', 0)):
             create_test_index(TESTS_TMP_PATH, config, True)
 
+    #check git version
+    check_git_version()
+
     # MULTIPLE DB configs
     # Setup the SQLAlchemy database engine
     sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
--- a/rhodecode/controllers/admin/settings.py	Tue Oct 02 20:15:07 2012 +0200
+++ b/rhodecode/controllers/admin/settings.py	Tue Oct 02 21:32:00 2012 +0200
@@ -41,7 +41,7 @@
 from rhodecode.lib.base import BaseController, render
 from rhodecode.lib.celerylib import tasks, run_task
 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
-    set_rhodecode_config, repo_name_slug
+    set_rhodecode_config, repo_name_slug, check_git_version
 from rhodecode.model.db import RhodeCodeUi, Repository, RepoGroup, \
     RhodeCodeSetting, PullRequest, PullRequestReviewers
 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
@@ -68,7 +68,8 @@
         c.admin_user = session.get('admin_user')
         c.admin_username = session.get('admin_username')
         c.modules = sorted([(p.project_name, p.version)
-                            for p in pkg_resources.working_set],
+                            for p in pkg_resources.working_set]
+                           + [('git', check_git_version())],
                            key=lambda k: k[0].lower())
         c.py_version = platform.python_version()
         c.platform = platform.platform()
--- a/rhodecode/lib/utils.py	Tue Oct 02 20:15:07 2012 +0200
+++ b/rhodecode/lib/utils.py	Tue Oct 02 21:32:00 2012 +0200
@@ -672,3 +672,38 @@
         self.path_to_ini_file = os.path.realpath(conf)
         conf = paste.deploy.appconfig('config:' + self.path_to_ini_file)
         pylonsconfig.init_app(conf.global_conf, conf.local_conf)
+
+
+def check_git_version():
+    """
+    Checks what version of git is installed in system, and issues a warning
+    if it's to old for RhodeCode to properly work.
+    """
+    import subprocess
+    from distutils.version import StrictVersion
+    from rhodecode import BACKENDS
+
+    p = subprocess.Popen('git --version', shell=True,
+                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    stdout, stderr = p.communicate()
+    ver = (stdout.split(' ')[-1] or '').strip() or '0.0.0'
+    try:
+        _ver = StrictVersion(ver)
+    except:
+        _ver = StrictVersion('0.0.0')
+        stderr = traceback.format_exc()
+
+    req_ver = '1.7.4'
+    to_old_git = False
+    if  _ver <= StrictVersion(req_ver):
+        to_old_git = True
+
+    if 'git' in BACKENDS:
+        log.debug('GIT version detected: %s' % stdout)
+        if stderr:
+            log.warning('Unable to detect git version org error was:%r' % stderr)
+        elif to_old_git:
+            log.warning('RhodeCode detected git version %s, which is to old '
+                        'for the system to function properly make sure '
+                        'it is at least in version %s' % (ver, req_ver))
+    return _ver
\ No newline at end of file