Skip to content

Commit 8d18c47

Browse files
cclaussjeking3
authored andcommitted
Update cmd.py, fix PermissionError issue using best practices
This closes #830
1 parent c045246 commit 8d18c47

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

git/cmd.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
stream_copy,
4444
)
4545

46+
try:
47+
PermissionError
48+
except NameError: # Python < 3.3
49+
PermissionError = OSError
4650

4751
execute_kwargs = {'istream', 'with_extended_output',
4852
'with_exceptions', 'as_process', 'stdout_as_string',
@@ -211,23 +215,15 @@ def refresh(cls, path=None):
211215

212216
# test if the new git executable path is valid
213217

214-
if sys.version_info < (3,):
215-
# - a GitCommandNotFound error is spawned by ourselves
216-
# - a OSError is spawned if the git executable provided
217-
# cannot be executed for whatever reason
218-
exceptions = (GitCommandNotFound, OSError)
219-
else:
220-
# - a GitCommandNotFound error is spawned by ourselves
221-
# - a PermissionError is spawned if the git executable provided
222-
# cannot be executed for whatever reason
223-
exceptions = (GitCommandNotFound, PermissionError) # noqa
224-
# (silence erroneous flake8 F821)
225-
218+
# - a GitCommandNotFound error is spawned by ourselves
219+
# - a PermissionError is spawned if the git executable provided
220+
# cannot be executed for whatever reason
221+
226222
has_git = False
227223
try:
228224
cls().version()
229225
has_git = True
230-
except exceptions:
226+
except (GitCommandNotFound, PermissionError):
231227
pass
232228

233229
# warn or raise exception if test failed

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy