From 90dc03da3ebe1daafd7f39d1255565b5c07757cb Mon Sep 17 00:00:00 2001 From: "Odegard, Ken" Date: Wed, 26 Jul 2017 07:52:16 -0500 Subject: Minor bug fixes Added tilde expansion as part of the refresh function. Added python version check such that we properly capture PermissionError in Python >=3 and OSError in Python <3. --- git/cmd.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index 329ad434..232450cb 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -203,7 +203,8 @@ class Git(LazyMixin): """ # discern which path to refresh with if path is not None: - new_git = os.path.abspath(path) + new_git = os.path.expanduser(path) + new_git = os.path.abspath(new_git) else: new_git = os.environ.get(cls._git_exec_env_var, cls.git_exec_name) @@ -212,14 +213,23 @@ class Git(LazyMixin): cls.GIT_PYTHON_GIT_EXECUTABLE = new_git # test if the new git executable path is valid + + if sys.version_info < (3,): + # - a GitCommandNotFound error is spawned by ourselves + # - a OSError is spawned if the git executable provided + # cannot be executed for whatever reason + exceptions = (GitCommandNotFound, OSError) + else: + # - a GitCommandNotFound error is spawned by ourselves + # - a PermissionError is spawned if the git executable provided + # cannot be executed for whatever reason + exceptions = (GitCommandNotFound, PermissionError) + has_git = False try: cls().version() has_git = True - except (GitCommandNotFound, PermissionError): - # - a GitCommandNotFound error is spawned by ourselves - # - a PermissionError is spawned if the git executable provided - # cannot be executed for whatever reason + except exceptions: pass # warn or raise exception if test failed -- cgit v1.2.1