Merge pull request #903 from pre-commit/relative_chdir_try_repo

Fix try-repo relpath while in a sub-directory
This commit is contained in:
Anthony Sottile
2019-01-01 12:35:00 -08:00
committed by GitHub
2 changed files with 15 additions and 0 deletions

View File

@@ -94,12 +94,16 @@ def _adjust_args_and_chdir(args):
args.config = os.path.abspath(args.config)
if args.command in {'run', 'try-repo'}:
args.files = [os.path.abspath(filename) for filename in args.files]
if args.command == 'try-repo' and os.path.exists(args.repo):
args.repo = os.path.abspath(args.repo)
os.chdir(git.get_root())
args.config = os.path.relpath(args.config)
if args.command in {'run', 'try-repo'}:
args.files = [os.path.relpath(filename) for filename in args.files]
if args.command == 'try-repo' and os.path.exists(args.repo):
args.repo = os.path.relpath(args.repo)
def main(argv=None):

View File

@@ -47,6 +47,17 @@ def test_adjust_args_and_chdir_non_relative_config(in_git_dir):
assert args.config == C.CONFIG_FILE
def test_adjust_args_try_repo_repo_relative(in_git_dir):
in_git_dir.join('foo').ensure_dir().chdir()
args = Args(command='try-repo', repo='../foo', files=[])
assert os.path.exists(args.repo)
main._adjust_args_and_chdir(args)
assert os.getcwd() == in_git_dir
assert os.path.exists(args.repo)
assert args.repo == 'foo'
FNS = (
'autoupdate', 'clean', 'install', 'install_hooks', 'migrate_config', 'run',
'sample_config', 'uninstall',