GitRepository: fix merge() for older git versions
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Apr 2012 11:51:18 +0000 (14:51 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 8 May 2012 08:39:39 +0000 (11:39 +0300)
Adds a new method for getting the version of git suite (i.e. git utils)
installed on the OS running gbp.

Utilize the new function in GitRepository.merge() to not give
edit/no-edit option for older versions of git-merge, that don't support
it. Fixes a regression (with git-version < 1.7.8) caused by commit
f3aa87fa0361a.

gbp/git/repository.py

index 2cc5edae385414e4187221d84a6d25cb64761183..1331907106818cbabd185f411f1a1cb7aeef092c 100644 (file)
@@ -157,6 +157,26 @@ class GitRepository(object):
         """
         GitCommand(command, args, extra_env=extra_env, cwd=self.path)()
 
+    def _get_git_version(self):
+        """
+        Return the version of the git suite (i.e. "git client commands")
+        that is installed on the OS.
+
+        The version is not a property of the git repository itself, but the
+        information it is needed in some methods of GitRepository() in order
+        to call git subcommands with correct arguments.
+
+        @return: git version
+        @rtype: C{str}
+        """
+        out = self._git_inout("version", [])
+        # effectively "lstrip" everything until the first number
+        version_re = re.compile(r'^[^0-9]*(?P<version>.*)$')
+        m = version_re.match(out[0])
+        if m:
+            return m.group('version')
+        return None
+
     @property
     def path(self):
         """The absolute path to the repository"""
@@ -312,7 +332,10 @@ class GitRepository(object):
         """
         args = GitArgs()
         args.add_cond(verbose, '--summary', '--no-summary')
-        args.add_cond(edit, '--edit', '--no-edit')
+        if (self._get_git_version() >= '1.7.8'):
+            args.add_cond(edit, '--edit', '--no-edit')
+        else:
+            log.debug("edit/no-edit option for git-merge not supported by your git suite version")
         args.add(commit)
         self._git_command("merge", args.args)