Catch BadName exceptions from newer GitPython

Catch the BadName exception raised by newer GitPython and gitdb versions
while ensuring that we still retain compatibility with older versions
that did not either contain this exception nor raise it.

To handle a new exception where it doesn't exist in the older codebase
simply set the value to None as except has no problem in matching
against non-existing exceptions.

Change-Id: Idf1f3e776317ad7a346364b9fadb4bc613bf2673
This commit is contained in:
Spencer Krum
2015-01-20 18:39:45 -08:00
committed by Darragh Bailey
parent 614507e04d
commit 964d5c784e
2 changed files with 12 additions and 2 deletions

View File

@@ -25,6 +25,11 @@ from git import BadObject
import inspect import inspect
import re import re
try:
from git import BadName
except ImportError:
BadName = None
class DropError(GitUpstreamError): class DropError(GitUpstreamError):
"""Exception thrown by L{Drop}""" """Exception thrown by L{Drop}"""
@@ -60,7 +65,7 @@ class Drop(LogDedentMixin, GitMixin):
try: try:
# test commit "id" presence # test commit "id" presence
self._commit = self.repo.commit(git_object) self._commit = self.repo.commit(git_object)
except BadObject: except (BadName, BadObject):
raise DropError( raise DropError(
"Commit '%s' not found (or ambiguous)" % git_object) "Commit '%s' not found (or ambiguous)" % git_object)

View File

@@ -27,6 +27,11 @@ from git import BadObject, Head
import inspect import inspect
import re import re
try:
from git import BadName
except ImportError:
BadName = None
class SupersedeError(GitUpstreamError): class SupersedeError(GitUpstreamError):
"""Exception thrown by L{Supersede}""" """Exception thrown by L{Supersede}"""
@@ -78,7 +83,7 @@ class Supersede(LogDedentMixin, GitMixin):
try: try:
# test commit "id" presence # test commit "id" presence
self._commit = self.repo.commit(git_object) self._commit = self.repo.commit(git_object)
except BadObject: except (BadName, BadObject):
raise SupersedeError("Commit '%s' not found (or ambiguous)" % raise SupersedeError("Commit '%s' not found (or ambiguous)" %
git_object) git_object)