mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Handle missing components in path canonicalization
The trailing components are not guarantee to exist. Avoid doing a second stat, just ignore FileNotFoundError exceptions in _canon_subpath.
This commit is contained in:
parent
037bc078dc
commit
58e1f625ab
1 changed files with 5 additions and 2 deletions
|
|
@ -159,8 +159,11 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
|||
def _canon_subpath(path: str, toplevel: str) -> str:
|
||||
tail = ''
|
||||
while len(path):
|
||||
if os.path.samefile(path, toplevel):
|
||||
return os.path.join(toplevel, tail)
|
||||
try:
|
||||
if os.path.samefile(path, toplevel):
|
||||
return os.path.join(toplevel, tail)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
path, base = os.path.split(path)
|
||||
tail = os.path.join(base, tail)
|
||||
return tail
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue