summaryrefslogtreecommitdiff
path: root/flake8/hooks.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2015-12-17 08:35:50 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2015-12-17 08:35:50 -0600
commitfa1105aaac3f00cb2b7b7dea092f3b6541769753 (patch)
tree93297822bf21e6a154dd83a70d52ebb7a3a1021e /flake8/hooks.py
parent4da31aa521fe0c66c2577f49cb7002a8d438bfbf (diff)
downloadflake8-fa1105aaac3f00cb2b7b7dea092f3b6541769753.tar.gz
Isolate the commands that raise OSError
Right now, running the git and hg commands could easily raise an OSError. Let's only catch it in those cases and then use else to install hooks when those are successful. Otherwise, pass on to the next supported VCS
Diffstat (limited to 'flake8/hooks.py')
-rw-r--r--flake8/hooks.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/flake8/hooks.py b/flake8/hooks.py
index c25b9aa..14f844e 100644
--- a/flake8/hooks.py
+++ b/flake8/hooks.py
@@ -157,18 +157,20 @@ def _get_files(repo, **kwargs):
def find_vcs():
try:
_, git_dir, _ = run('git rev-parse --git-dir')
+ except OSError:
+ pass
+ else:
if git_dir and os.path.isdir(git_dir[0]):
if not os.path.isdir(os.path.join(git_dir[0], 'hooks')):
os.mkdir(os.path.join(git_dir[0], 'hooks'))
return os.path.join(git_dir[0], 'hooks', 'pre-commit')
- except OSError:
- pass
try:
_, hg_dir, _ = run('hg root')
- if hg_dir and os.path.isdir(hg_dir[0]):
- return os.path.join(hg_dir[0], '.hg', 'hgrc')
except OSError:
pass
+ else:
+ if hg_dir and os.path.isdir(hg_dir[0]):
+ return os.path.join(hg_dir[0], '.hg', 'hgrc')
return ''