fixed git errors issues, thanks Alan, wonderful work

This commit is contained in:
Massimo
2013-01-15 13:08:27 -06:00
parent c1a534bee2
commit 1c69eb4ce4
2 changed files with 38 additions and 27 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.1-alpha.2+timestamp.2013.01.14.15.29.20 Version 2.4.1-alpha.2+timestamp.2013.01.15.13.07.36
+37 -26
View File
@@ -15,7 +15,13 @@ from glob import glob
import shutil import shutil
import platform import platform
try: try:
from git import * import git
GIT_ERRORS = (git.GitCommandError, git.InvalidGitRepositoryError,
git.NoSuchPathError)
if git.__version__ >= '0.3.1':
GIT_ERRORS += (git.CacheError, git.CheckoutError,
git.ODBError, git.ParseError,
git.UnmergedEntriesError)
have_git = True have_git = True
except ImportError: except ImportError:
have_git = False have_git = False
@@ -240,10 +246,10 @@ def site():
redirect(URL(r=request)) redirect(URL(r=request))
target = os.path.join(apath(r=request), form_update.vars.name) target = os.path.join(apath(r=request), form_update.vars.name)
try: try:
new_repo = Repo.clone_from(form_update.vars.url, target) new_repo = git.Repo.clone_from(form_update.vars.url, target)
session.flash = T('new application "%s" imported', session.flash = T('new application "%s" imported',
form_update.vars.name) form_update.vars.name)
except GitCommandError, err: except git.GitCommandError, err:
session.flash = T('Invalid git repository specified.') session.flash = T('Invalid git repository specified.')
redirect(URL(r=request)) redirect(URL(r=request))
@@ -1726,29 +1732,31 @@ def git_pull():
{T('Cancel'): URL('site')}) {T('Cancel'): URL('site')})
if dialog.accepted: if dialog.accepted:
try: try:
repo = Repo(os.path.join(apath(r=request), app)) repo = git.Repo(os.path.join(apath(r=request), app))
origin = repo.remotes.origin origin = repo.remotes.origin
origin.fetch() origin.fetch()
origin.pull() origin.pull()
session.flash = T("Application updated via git pull") session.flash = T("Application updated via git pull")
redirect(URL('site')) redirect(URL('site'))
except CheckoutError, message: except GIT_ERRORS, e:
session.flash = T("Pull failed, certain files could not be checked out. Check logs for details.") error_type = type(e)
redirect(URL('site')) if 'CheckoutError' in error_type:
except UnmergedEntriesError: session.flash = T("Pull failed, certain files could not be checked out. Check logs for details.")
session.flash = T("Pull is not possible because you have unmerged files. Fix them up in the work tree, and then try again.") redirect(URL('site'))
redirect(URL('site')) elif 'UnmergedEntriesError' in error_type:
session.flash = T("Pull is not possible because you have unmerged files. Fix them up in the work tree, and then try again.")
redirect(URL('site'))
elif 'GitCommandError' in error_type:
session.flash = T(
"Pull failed, git exited abnormally. See logs for details.")
redirect(URL('site'))
else:
session.flash = T(
"Git error: %s %s" % (error_type, str(e)))
redirect(URL('site'))
except AssertionError: except AssertionError:
session.flash = T("Pull is not possible because you have unmerged files. Fix them up in the work tree, and then try again.") session.flash = T("Pull is not possible because you have unmerged files. Fix them up in the work tree, and then try again.")
redirect(URL('site')) redirect(URL('site'))
except GitCommandError, status:
session.flash = T(
"Pull failed, git exited abnormally. See logs for details.")
redirect(URL('site'))
except Exception, e:
session.flash = T(
"Pull failed, git exited abnormally. See logs for details.")
redirect(URL('site'))
elif 'cancel' in request.vars: elif 'cancel' in request.vars:
redirect(URL('site')) redirect(URL('site'))
return dict(app=app, dialog=dialog) return dict(app=app, dialog=dialog)
@@ -1766,7 +1774,7 @@ def git_push():
form.process() form.process()
if form.accepted: if form.accepted:
try: try:
repo = Repo(os.path.join(apath(r=request), app)) repo = git.Repo(os.path.join(apath(r=request), app))
index = repo.index index = repo.index
index.add([apath(r=request) + app + '/*']) index.add([apath(r=request) + app + '/*'])
new_commit = index.commit(form.vars.changelog) new_commit = index.commit(form.vars.changelog)
@@ -1775,11 +1783,14 @@ def git_push():
session.flash = T( session.flash = T(
"Git repo updated with latest application changes.") "Git repo updated with latest application changes.")
redirect(URL('site')) redirect(URL('site'))
except UnmergedEntriesError: except GIT_ERRORS, e:
session.flash = T("Push failed, there are unmerged entries in the cache. Resolve merge issues manually and try again.") error_type = type(e)
redirect(URL('site')) if "UnmergedEntriesError" in error_type:
except Exception, e: session.flash = T("Push failed, there are unmerged entries in the cache. Resolve merge issues manually and try again.")
session.flash = T( redirect(URL('site'))
"Push failed, git exited abnormally. See logs for details.") else:
redirect(URL('site')) session.flash = T(
"Git error: %s %s" % (error_type, str(e)))
redirect(URL('site'))
return dict(app=app, form=form) return dict(app=app, form=form)