mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
Add a --tags-only option to autoupdate
This commit is contained in:
@@ -21,7 +21,7 @@ class RepositoryCannotBeUpdatedError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _update_repository(repo_config, runner):
|
||||
def _update_repo(repo_config, runner, tags_only):
|
||||
"""Updates a repository to the tip of `master`. If the repository cannot
|
||||
be updated because a hook that is configured does not exist in `master`,
|
||||
this raises a RepositoryCannotBeUpdatedError
|
||||
@@ -33,10 +33,13 @@ def _update_repository(repo_config, runner):
|
||||
|
||||
with cwd(repo.repo_path_getter.repo_path):
|
||||
cmd_output('git', 'fetch')
|
||||
tag_cmd = ('git', 'describe', 'origin/master', '--tags')
|
||||
if tags_only:
|
||||
tag_cmd += ('--abbrev=0',)
|
||||
else:
|
||||
tag_cmd += ('--exact',)
|
||||
try:
|
||||
rev = cmd_output(
|
||||
'git', 'describe', 'origin/master', '--tags', '--exact',
|
||||
)[1].strip()
|
||||
rev = cmd_output(*tag_cmd)[1].strip()
|
||||
except CalledProcessError:
|
||||
rev = cmd_output('git', 'rev-parse', 'origin/master')[1].strip()
|
||||
|
||||
@@ -61,7 +64,7 @@ def _update_repository(repo_config, runner):
|
||||
return new_config
|
||||
|
||||
|
||||
def autoupdate(runner):
|
||||
def autoupdate(runner, tags_only):
|
||||
"""Auto-update the pre-commit config to the latest versions of repos."""
|
||||
retv = 0
|
||||
output_configs = []
|
||||
@@ -78,7 +81,7 @@ def autoupdate(runner):
|
||||
continue
|
||||
output.write('Updating {}...'.format(repo_config['repo']))
|
||||
try:
|
||||
new_repo_config = _update_repository(repo_config, runner)
|
||||
new_repo_config = _update_repo(repo_config, runner, tags_only)
|
||||
except RepositoryCannotBeUpdatedError as error:
|
||||
output.write_line(error.args[0])
|
||||
output_configs.append(repo_config)
|
||||
|
||||
@@ -111,6 +111,9 @@ def main(argv=None):
|
||||
)
|
||||
_add_color_option(autoupdate_parser)
|
||||
_add_config_option(autoupdate_parser)
|
||||
autoupdate_parser.add_argument(
|
||||
'--tags-only', action='store_true', help='Update to tags only.',
|
||||
)
|
||||
|
||||
run_parser = subparsers.add_parser('run', help='Run hooks.')
|
||||
_add_color_option(run_parser)
|
||||
@@ -190,7 +193,7 @@ def main(argv=None):
|
||||
elif args.command == 'clean':
|
||||
return clean(runner)
|
||||
elif args.command == 'autoupdate':
|
||||
return autoupdate(runner)
|
||||
return autoupdate(runner, args.tags_only)
|
||||
elif args.command == 'run':
|
||||
return run(runner, args)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user