mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Use os.path.realpath() for path canonicalization
os.getcwd() returns the real path of the current working directory. In a directory which has been symlinked this does not necessarily match the same prefix of the current directory. When os.getcwd() is cd-ed to relativize path names a few lines below this results in paths which are relative to symlinked tree, not to the real tree. This makes path rule matches fail. Use os.path.realpath() when making paths absolute, so that relative paths refer to the same tree as os.getcwd()
This commit is contained in:
parent
d021bbfabd
commit
1bf65b37c6
1 changed files with 3 additions and 3 deletions
|
|
@ -159,11 +159,11 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
||||||
def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
|
def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
|
||||||
# `--config` was specified relative to the non-root working directory
|
# `--config` was specified relative to the non-root working directory
|
||||||
if os.path.exists(args.config):
|
if os.path.exists(args.config):
|
||||||
args.config = os.path.abspath(args.config)
|
args.config = os.path.realpath(args.config)
|
||||||
if args.command in {'run', 'try-repo'}:
|
if args.command in {'run', 'try-repo'}:
|
||||||
args.files = [os.path.abspath(filename) for filename in args.files]
|
args.files = [os.path.realpath(filename) for filename in args.files]
|
||||||
if args.command == 'try-repo' and os.path.exists(args.repo):
|
if args.command == 'try-repo' and os.path.exists(args.repo):
|
||||||
args.repo = os.path.abspath(args.repo)
|
args.repo = os.path.realpath(args.repo)
|
||||||
|
|
||||||
toplevel = git.get_root()
|
toplevel = git.get_root()
|
||||||
os.chdir(toplevel)
|
os.chdir(toplevel)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue