From 8998685140981c0779fa7bd0cfa34f41f09f6a9e Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Wed, 18 May 2011 21:42:43 +0900
Subject: [PATCH] Handle git command execution error.

Like SubversionClient, display a readable error message when git command could
not be executed.
---
 product/ERP5VCS/Git.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/product/ERP5VCS/Git.py b/product/ERP5VCS/Git.py
index 00fa226b62..7cb49b99cd 100644
--- a/product/ERP5VCS/Git.py
+++ b/product/ERP5VCS/Git.py
@@ -39,6 +39,10 @@ from Products.ERP5VCS.WorkingCopy import \
 # TODO: write a similar helper for 'nt' platform
 GIT_ASKPASS = os.path.join(os.path.dirname(__file__), 'bin', 'git_askpass')
 
+class GitInstallationError(EnvironmentError):
+  """Raised when an installation is broken"""
+  pass
+
 class GitError(EnvironmentError):
   def __init__(self, err, out, returncode):
     EnvironmentError.__init__(self, err)
@@ -61,7 +65,18 @@ class Git(WorkingCopy):
   def _git(self, *args, **kw):
     kw.setdefault('cwd', self.working_copy)
     argv = ['git']
-    return subprocess.Popen(argv + list(args), **kw)
+    try:
+      return subprocess.Popen(argv + list(args), **kw)
+    except OSError, e:
+      import sys
+      from zLOG import LOG, WARNING
+      LOG('Git', WARNING,
+          'will not work as the executable cannot be executed, perhaps not '
+          'in the Zope PATH or because of permissions.',
+          error=sys.exc_info())
+
+      raise GitInstallationError("git command cannot be executed: %s" % \
+                                   e.strerror)
 
   security.declarePrivate('git')
   def git(self, *args, **kw):
-- 
2.30.9