mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 02:46:52 +00:00
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
This commit is contained in:
parent
4da31aa521
commit
fa1105aaac
1 changed files with 6 additions and 4 deletions
|
|
@ -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 ''
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue