mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #657 from KevinHock/master
Add repo option to autoupdate
This commit is contained in:
commit
311eddf0f9
3 changed files with 50 additions and 2 deletions
|
|
@ -106,7 +106,7 @@ def _write_new_config_file(path, output):
|
||||||
f.write(to_write)
|
f.write(to_write)
|
||||||
|
|
||||||
|
|
||||||
def autoupdate(runner, tags_only):
|
def autoupdate(runner, tags_only, repo=None):
|
||||||
"""Auto-update the pre-commit config to the latest versions of repos."""
|
"""Auto-update the pre-commit config to the latest versions of repos."""
|
||||||
migrate_config(runner, quiet=True)
|
migrate_config(runner, quiet=True)
|
||||||
retv = 0
|
retv = 0
|
||||||
|
|
@ -116,6 +116,10 @@ def autoupdate(runner, tags_only):
|
||||||
input_config = load_config(runner.config_file_path)
|
input_config = load_config(runner.config_file_path)
|
||||||
|
|
||||||
for repo_config in input_config['repos']:
|
for repo_config in input_config['repos']:
|
||||||
|
# Skip any repo_configs that aren't the specified repo
|
||||||
|
if repo and repo != repo_config['repo']:
|
||||||
|
continue
|
||||||
|
|
||||||
if is_local_repo(repo_config) or is_meta_repo(repo_config):
|
if is_local_repo(repo_config) or is_meta_repo(repo_config):
|
||||||
output_repos.append(repo_config)
|
output_repos.append(repo_config)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,9 @@ def main(argv=None):
|
||||||
'tagged version (the default behavior).'
|
'tagged version (the default behavior).'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
autoupdate_parser.add_argument(
|
||||||
|
'--repo', help='Only update this repository.',
|
||||||
|
)
|
||||||
|
|
||||||
migrate_config_parser = subparsers.add_parser(
|
migrate_config_parser = subparsers.add_parser(
|
||||||
'migrate-config',
|
'migrate-config',
|
||||||
|
|
@ -245,7 +248,11 @@ def main(argv=None):
|
||||||
elif args.command == 'autoupdate':
|
elif args.command == 'autoupdate':
|
||||||
if args.tags_only:
|
if args.tags_only:
|
||||||
logger.warning('--tags-only is the default')
|
logger.warning('--tags-only is the default')
|
||||||
return autoupdate(runner, tags_only=not args.bleeding_edge)
|
return autoupdate(
|
||||||
|
runner,
|
||||||
|
tags_only=not args.bleeding_edge,
|
||||||
|
repo=args.repo,
|
||||||
|
)
|
||||||
elif args.command == 'migrate-config':
|
elif args.command == 'migrate-config':
|
||||||
return migrate_config(runner)
|
return migrate_config(runner)
|
||||||
elif args.command == 'run':
|
elif args.command == 'run':
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,43 @@ def test_autoupdate_out_of_date_repo(
|
||||||
assert out_of_date_repo.head_sha in after
|
assert out_of_date_repo.head_sha in after
|
||||||
|
|
||||||
|
|
||||||
|
def test_autoupdate_out_of_date_repo_with_correct_repo_name(
|
||||||
|
out_of_date_repo, in_tmpdir, mock_out_store_directory,
|
||||||
|
):
|
||||||
|
# Write out the config
|
||||||
|
config = make_config_from_repo(
|
||||||
|
out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False,
|
||||||
|
)
|
||||||
|
write_config('.', config)
|
||||||
|
|
||||||
|
runner = Runner('.', C.CONFIG_FILE)
|
||||||
|
before = open(C.CONFIG_FILE).read()
|
||||||
|
repo_name = 'file://{}'.format(out_of_date_repo.path)
|
||||||
|
ret = autoupdate(runner, tags_only=False, repo=repo_name)
|
||||||
|
after = open(C.CONFIG_FILE).read()
|
||||||
|
assert ret == 0
|
||||||
|
assert before != after
|
||||||
|
assert out_of_date_repo.head_sha in after
|
||||||
|
|
||||||
|
|
||||||
|
def test_autoupdate_out_of_date_repo_with_wrong_repo_name(
|
||||||
|
out_of_date_repo, in_tmpdir, mock_out_store_directory,
|
||||||
|
):
|
||||||
|
# Write out the config
|
||||||
|
config = make_config_from_repo(
|
||||||
|
out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False,
|
||||||
|
)
|
||||||
|
write_config('.', config)
|
||||||
|
|
||||||
|
runner = Runner('.', C.CONFIG_FILE)
|
||||||
|
before = open(C.CONFIG_FILE).read()
|
||||||
|
# It will not update it, because the name doesn't match
|
||||||
|
ret = autoupdate(runner, tags_only=False, repo='wrong_repo_name')
|
||||||
|
after = open(C.CONFIG_FILE).read()
|
||||||
|
assert ret == 0
|
||||||
|
assert before == after
|
||||||
|
|
||||||
|
|
||||||
def test_does_not_reformat(
|
def test_does_not_reformat(
|
||||||
out_of_date_repo, mock_out_store_directory, in_tmpdir,
|
out_of_date_repo, mock_out_store_directory, in_tmpdir,
|
||||||
):
|
):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue