From 964d5c784e945132f7355b4882f3a37160e6bda5 Mon Sep 17 00:00:00 2001 From: Spencer Krum Date: Tue, 20 Jan 2015 18:39:45 -0800 Subject: [PATCH] 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 --- git_upstream/commands/drop.py | 7 ++++++- git_upstream/commands/supersede.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/git_upstream/commands/drop.py b/git_upstream/commands/drop.py index dd34956..1edf6af 100644 --- a/git_upstream/commands/drop.py +++ b/git_upstream/commands/drop.py @@ -25,6 +25,11 @@ from git import BadObject import inspect import re +try: + from git import BadName +except ImportError: + BadName = None + class DropError(GitUpstreamError): """Exception thrown by L{Drop}""" @@ -60,7 +65,7 @@ class Drop(LogDedentMixin, GitMixin): try: # test commit "id" presence self._commit = self.repo.commit(git_object) - except BadObject: + except (BadName, BadObject): raise DropError( "Commit '%s' not found (or ambiguous)" % git_object) diff --git a/git_upstream/commands/supersede.py b/git_upstream/commands/supersede.py index 70093ef..7db3464 100644 --- a/git_upstream/commands/supersede.py +++ b/git_upstream/commands/supersede.py @@ -27,6 +27,11 @@ from git import BadObject, Head import inspect import re +try: + from git import BadName +except ImportError: + BadName = None + class SupersedeError(GitUpstreamError): """Exception thrown by L{Supersede}""" @@ -78,7 +83,7 @@ class Supersede(LogDedentMixin, GitMixin): try: # test commit "id" presence self._commit = self.repo.commit(git_object) - except BadObject: + except (BadName, BadObject): raise SupersedeError("Commit '%s' not found (or ambiguous)" % git_object)