diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b87a406..8a5dbef9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,7 +36,9 @@ repos: rev: v1.0.0 hooks: - id: add-trailing-comma -- repo: meta - hooks: - - id: check-hooks-apply - - id: check-useless-excludes +- repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + - id: identity + - id: sign-commit diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py index 2f16650a..02105916 100644 --- a/pre_commit/clientlib.py +++ b/pre_commit/clientlib.py @@ -166,6 +166,13 @@ _meta = ( ('entry', _entry('identity')), ), ), + ( + 'sign-commit', ( + ('name', 'identity'), + ('verbose', True), + ('entry', _entry('identity')), + ), + ), ) META_HOOK_DICT = cfgv.Map( diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index d060e186..b6944483 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -73,7 +73,7 @@ SKIPPED = 'Skipped' NO_FILES = '(no files to check)' -def _run_single_hook(classifier, hook, args, skips, cols): +def _run_single_hook(classifier, hook, args, skips, cols, retval): filenames = classifier.filenames_for_hook(hook) if hook.language == 'pcre': @@ -211,7 +211,8 @@ def _run_hooks(config, hooks, args, environ): classifier = Classifier(filenames) retval = 0 for hook in hooks: - retval |= _run_single_hook(classifier, hook, args, skips, cols) + args + retval |= _run_single_hook(classifier, hook, args, skips, cols, retval) if retval and config['fail_fast']: break if retval and args.show_diff_on_failure and git.has_diff(): diff --git a/pre_commit/meta_hooks/sign_commit.py b/pre_commit/meta_hooks/sign_commit.py new file mode 100644 index 00000000..f0ae6341 --- /dev/null +++ b/pre_commit/meta_hooks/sign_commit.py @@ -0,0 +1,21 @@ +import argparse + +from pre_commit import output + + +def sign_commit(): + pass + + +def main(argv=None): + parser = argparse.ArgumentParser() + parser.add_argument('retval', nargs='*', default=0) + args = parser.parse_args(argv) + output.write_line(f'Signing commit message if {args.retval}') + if args.retval: + return 1 + return 0 + + +if __name__ == '__main__': + exit(main())