From d3ae7918c7d500a8c9a99d4c6f7fb41ee3661fee Mon Sep 17 00:00:00 2001 From: Julien Muchembled <jm@nexedi.com> Date: Mon, 14 Mar 2011 17:20:08 +0000 Subject: [PATCH] Fix ClientError/GitError when exporting a new Business Template git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44256 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5VCS/Git.py | 12 +++++++++--- product/ERP5VCS/Subversion.py | 13 +++++++++---- product/ERP5VCS/WorkingCopy.py | 8 +++++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/product/ERP5VCS/Git.py b/product/ERP5VCS/Git.py index bb3bc732d6..aacc1055fc 100644 --- a/product/ERP5VCS/Git.py +++ b/product/ERP5VCS/Git.py @@ -33,7 +33,7 @@ from DateTime import DateTime from Products.ERP5Type.Message import translateString from ZTUtils import make_query from Products.ERP5VCS.WorkingCopy import \ - WorkingCopy, NotAWorkingCopyError, Dir, File, selfcached + WorkingCopy, NotAWorkingCopyError, NotVersionedError, Dir, File, selfcached class GitError(EnvironmentError): def __init__(self, err, out, returncode): @@ -223,8 +223,14 @@ class Git(WorkingCopy): return self.aq_parent.download(self.working_copy) def showOld(self, path): - return self.git('show', 'HEAD:' + self.prefix + path, - strip=False, cwd=self.toplevel) + try: + return self.git('show', 'HEAD:' + self.prefix + path, + strip=False, cwd=self.toplevel) + except GitError, e: + err = e.args[0] + if ' does not exist in ' in err or ' exists on disk, but not in ' in err: + raise NotVersionedError(path) + raise def getAuthor(self): portal = self.getPortalObject() diff --git a/product/ERP5VCS/Subversion.py b/product/ERP5VCS/Subversion.py index dda6d639ed..1340df94b0 100644 --- a/product/ERP5VCS/Subversion.py +++ b/product/ERP5VCS/Subversion.py @@ -37,7 +37,7 @@ from Products.ERP5Type.Message import translateString from Products.ERP5.Document.BusinessTemplate import BusinessTemplateFolder from Products.ERP5VCS.WorkingCopy import \ WorkingCopy, Dir, File, chdir_working_copy, selfcached, \ - NotAWorkingCopyError, VcsConflictError + NotAWorkingCopyError, NotVersionedError, VcsConflictError from Products.ERP5VCS.SubversionClient import \ newSubversionClient, SubversionLoginError, SubversionSSLTrustError @@ -139,9 +139,14 @@ class Subversion(WorkingCopy): return self.aq_parent.download('.') def showOld(self, path): - from pysvn import Revision, opt_revision_kind - return self._getClient().cat(os.path.join(self.working_copy, path), - Revision(opt_revision_kind.base)) + from pysvn import ClientError, Revision, opt_revision_kind, svn_err + try: + return self._getClient().cat(os.path.join(self.working_copy, path), + Revision(opt_revision_kind.base)) + except ClientError, e: + if e.args[1][-1][1] in (errno.ENOENT, svn_err.entry_not_found): + raise NotVersionedError(path) + raise @selfcached def info(self): diff --git a/product/ERP5VCS/WorkingCopy.py b/product/ERP5VCS/WorkingCopy.py index 4cd1ec4fe4..12b9aef960 100644 --- a/product/ERP5VCS/WorkingCopy.py +++ b/product/ERP5VCS/WorkingCopy.py @@ -72,6 +72,9 @@ def selfcached(func): class NotAWorkingCopyError(Exception): pass ModuleSecurityInfo(__name__).declarePublic('NotAWorkingCopyError') +class NotVersionedError(Exception): pass +ModuleSecurityInfo(__name__).declarePublic('NotVersionedError') + class BusinessTemplateNotInstalled(Exception): pass ModuleSecurityInfo(__name__).declarePublic('BusinessTemplateNotInstalled') @@ -200,7 +203,10 @@ class WorkingCopy(Implicit): def newRevision(self): path = os.path.join('bt', 'revision') - revision = int(self.showOld(path)) + 1 + try: + revision = int(self.showOld(path)) + 1 + except NotVersionedError: + return 1 file = open(os.path.join(self.working_copy, path), 'w') try: file.write(str(revision)) -- 2.30.9