Patchwork [stable] subrepo: factor out Git version check to add doctests

login
register
mail settings
Submitter Siddharth Agarwal
Date March 21, 2014, 11:13 p.m.
Message ID <c9293fbfc909a5ced442.1395443608@dev1738.prn1.facebook.com>
Download mbox | patch
Permalink /patch/4035/
State Superseded
Commit 308344d80fe558ec060bcaaac4e83a321d838810
Headers show

Comments

Siddharth Agarwal - March 21, 2014, 11:13 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1395443357 25200
#      Fri Mar 21 16:09:17 2014 -0700
# Node ID c9293fbfc909a5ced442e69a07eeffb066f96467
# Parent  3d1d16b19e7dd5e96e242daed86512429bc1d3f6
subrepo: factor out Git version check to add doctests

Followup to 6a2acb0d9352::e5641536e4d5.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1107,18 +1107,50 @@ 
                 raise
             self._gitexecutable = 'git.cmd'
             out, err = self._gitnodir(['--version'])
+        versionstatus = self._checkversion(out)
+        if versionstatus == 'unknown':
+            self._ui.warn(_('cannot retrieve git version\n'))
+        elif versionstatus == 'abort':
+            raise util.Abort(_('git subrepo requires at least 1.6.0 or later'))
+        elif versionstatus == 'warning':
+            self._ui.warn(_('git subrepo requires at least 1.6.0 or later\n'))
+
+    @staticmethod
+    def _checkversion(out):
+        '''ensure git version is new enough
+
+        >>> _checkversion = gitsubrepo._checkversion
+        >>> _checkversion('git version 1.6.0')
+        'ok'
+        >>> _checkversion('git version 1.8.5')
+        'ok'
+        >>> _checkversion('git version 1.4.0')
+        'abort'
+        >>> _checkversion('git version 1.5.0')
+        'warning'
+        >>> _checkversion('git version 1.9-rc0')
+        'ok'
+        >>> _checkversion('git version 1.9.0.265.g81cdec2')
+        'ok'
+        >>> _checkversion('git version 1.9.0.GIT')
+        'ok'
+        >>> _checkversion('git version 12345')
+        'unknown'
+        >>> _checkversion('no')
+        'unknown'
+        '''
         m = re.search(r'^git version (\d+)\.(\d+)', out)
         if not m:
-            self._ui.warn(_('cannot retrieve git version\n'))
-            return
+            return 'unknown'
         version = (int(m.group(1)), int(m.group(2)))
         # git 1.4.0 can't work at all, but 1.5.X can in at least some cases,
         # despite the docstring comment.  For now, error on 1.4.0, warn on
         # 1.5.0 but attempt to continue.
         if version < (1, 5):
-            raise util.Abort(_('git subrepo requires at least 1.6.0 or later'))
+            return 'abort'
         elif version < (1, 6):
-            self._ui.warn(_('git subrepo requires at least 1.6.0 or later\n'))
+            return 'warning'
+        return 'ok'
 
     def _gitcommand(self, commands, env=None, stream=False):
         return self._gitdir(commands, env=env, stream=stream)[0]
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -21,6 +21,7 @@ 
 testmod('mercurial.minirst')
 testmod('mercurial.revset')
 testmod('mercurial.store')
+testmod('mercurial.subrepo')
 testmod('mercurial.templatefilters')
 testmod('mercurial.ui')
 testmod('mercurial.url')