mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 04:50:20 -06:00
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:
@@ -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):
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user