mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 09:34:42 +04:00
Merge pull request #713 from pre-commit/update_many_repos
Allow autoupdate --repo to be specified multiple times
This commit is contained in:
commit
86da772fd2
3 changed files with 7 additions and 6 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, repo=None):
|
def autoupdate(runner, tags_only, repos=()):
|
||||||
"""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
|
||||||
|
|
@ -120,7 +120,7 @@ def autoupdate(runner, tags_only, repo=None):
|
||||||
is_local_repo(repo_config) or
|
is_local_repo(repo_config) or
|
||||||
is_meta_repo(repo_config) or
|
is_meta_repo(repo_config) or
|
||||||
# Skip updating any repo_configs that aren't for the specified repo
|
# Skip updating any repo_configs that aren't for the specified repo
|
||||||
repo and repo != repo_config['repo']
|
repos and repo_config['repo'] not in repos
|
||||||
):
|
):
|
||||||
output_repos.append(repo_config)
|
output_repos.append(repo_config)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,8 @@ def main(argv=None):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
autoupdate_parser.add_argument(
|
autoupdate_parser.add_argument(
|
||||||
'--repo', help='Only update this repository.',
|
'--repo', dest='repos', action='append', metavar='REPO',
|
||||||
|
help='Only update this repository -- may be specified multiple times.',
|
||||||
)
|
)
|
||||||
|
|
||||||
migrate_config_parser = subparsers.add_parser(
|
migrate_config_parser = subparsers.add_parser(
|
||||||
|
|
@ -251,7 +252,7 @@ def main(argv=None):
|
||||||
return autoupdate(
|
return autoupdate(
|
||||||
runner,
|
runner,
|
||||||
tags_only=not args.bleeding_edge,
|
tags_only=not args.bleeding_edge,
|
||||||
repo=args.repo,
|
repos=args.repos,
|
||||||
)
|
)
|
||||||
elif args.command == 'migrate-config':
|
elif args.command == 'migrate-config':
|
||||||
return migrate_config(runner)
|
return migrate_config(runner)
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ def test_autoupdate_out_of_date_repo_with_correct_repo_name(
|
||||||
runner = Runner('.', C.CONFIG_FILE)
|
runner = Runner('.', C.CONFIG_FILE)
|
||||||
before = open(C.CONFIG_FILE).read()
|
before = open(C.CONFIG_FILE).read()
|
||||||
repo_name = 'file://{}'.format(out_of_date_repo.path)
|
repo_name = 'file://{}'.format(out_of_date_repo.path)
|
||||||
ret = autoupdate(runner, tags_only=False, repo=repo_name)
|
ret = autoupdate(runner, tags_only=False, repos=(repo_name,))
|
||||||
after = open(C.CONFIG_FILE).read()
|
after = open(C.CONFIG_FILE).read()
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert before != after
|
assert before != after
|
||||||
|
|
@ -158,7 +158,7 @@ def test_autoupdate_out_of_date_repo_with_wrong_repo_name(
|
||||||
runner = Runner('.', C.CONFIG_FILE)
|
runner = Runner('.', C.CONFIG_FILE)
|
||||||
before = open(C.CONFIG_FILE).read()
|
before = open(C.CONFIG_FILE).read()
|
||||||
# It will not update it, because the name doesn't match
|
# It will not update it, because the name doesn't match
|
||||||
ret = autoupdate(runner, tags_only=False, repo='wrong_repo_name')
|
ret = autoupdate(runner, tags_only=False, repos=('wrong_repo_name',))
|
||||||
after = open(C.CONFIG_FILE).read()
|
after = open(C.CONFIG_FILE).read()
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert before == after
|
assert before == after
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue