Skip to content

Commit

Permalink
Change names of prepare-commit-msg args
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Whitaker committed May 29, 2022
1 parent 4866896 commit e3f2c88
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
34 changes: 17 additions & 17 deletions pre_commit/commands/hook_impl.py
Expand Up @@ -76,8 +76,8 @@ def _ns(
remote_name: str | None = None,
remote_url: str | None = None,
commit_msg_filename: str | None = None,
commit_msg: str | None = None,
commit_sha: str | None = None,
prepare_commit_message_source: str | None = None,
commit_object_name: str | None = None,
checkout_type: str | None = None,
is_squash_merge: str | None = None,
rewrite_command: str | None = None,
Expand All @@ -92,8 +92,8 @@ def _ns(
remote_name=remote_name,
remote_url=remote_url,
commit_msg_filename=commit_msg_filename,
commit_msg=commit_msg,
commit_sha=commit_sha,
prepare_commit_message_source=prepare_commit_message_source,
commit_object_name=commit_object_name,
all_files=all_files,
checkout_type=checkout_type,
is_squash_merge=is_squash_merge,
Expand Down Expand Up @@ -206,20 +206,20 @@ def _run_ns(
_check_args_length(hook_type, args)
if hook_type == 'pre-push':
return _pre_push_ns(color, args, stdin)
elif hook_type in 'commit-msg' or hook_type == 'prepare-commit-msg' and \
len(args) == 1:
elif hook_type in 'commit-msg':
return _ns(hook_type, color, commit_msg_filename=args[0])
elif hook_type == 'prepare-commit-msg' and len(args) > 1:
if (len(args) == 2):
return _ns(
hook_type, color, commit_msg_filename=args[0],
commit_msg=args[1],
)
else:
return _ns(
hook_type, color, commit_msg_filename=args[0],
commit_msg=args[1], commit_sha=args[2],
)
elif hook_type == 'prepare-commit-msg' and len(args) == 1:
return _ns(hook_type, color, commit_msg_filename=args[0])
elif hook_type == 'prepare-commit-msg' and len(args) == 2:
return _ns(
hook_type, color, commit_msg_filename=args[0],
prepare_commit_message_source=args[1],
)
elif hook_type == 'prepare-commit-msg' and len(args) == 3:
return _ns(
hook_type, color, commit_msg_filename=args[0],
prepare_commit_message_source=args[1], commit_object_name=args[2],
)
elif hook_type in {'post-commit', 'pre-merge-commit', 'pre-commit'}:
return _ns(hook_type, color)
elif hook_type == 'post-checkout':
Expand Down
14 changes: 8 additions & 6 deletions pre_commit/commands/run.py
Expand Up @@ -361,12 +361,14 @@ def run(
):
return 0

# Expose commit_msg / commit_sha as environment variables for the hooks
if args.commit_msg:
environ['PRE_COMMIT_COMMIT_MSG'] = args.commit_msg

if args.commit_sha:
environ['PRE_COMMIT_COMMIT_SHA'] = args.commit_sha
# Expose prepare_commit_message_source / commit_object_name
# as environment variables for the hooks
if args.prepare_commit_message_source:
environ['PRE_COMMIT_COMMIT_MSG_SOURCE'] \
= args.prepare_commit_message_source

if args.commit_object_name:
environ['PRE_COMMIT_COMMIT_OBJECT_NAME'] = args.commit_object_name

# Expose from-ref / to-ref as environment variables for hooks to consume
if args.from_ref and args.to_ref:
Expand Down
6 changes: 3 additions & 3 deletions pre_commit/main.py
Expand Up @@ -108,14 +108,14 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
help='Filename to check when running during `commit-msg`',
)
parser.add_argument(
'--commit-msg',
'--prepare-commit-message-source',
help=(
'Type of commit string to pass though as ENV' +
'Type of commit string to pass though as ENV ' +
'during `prepare-commit-msg`'
),
)
parser.add_argument(
'--commit-sha',
'--commit-object-name',
help='Commit sha to pass though as ENV during `prepare-commit-msg`',
)
parser.add_argument(
Expand Down
8 changes: 4 additions & 4 deletions testing/util.py
Expand Up @@ -76,8 +76,8 @@ def run_opts(
hook_stage='commit',
show_diff_on_failure=False,
commit_msg_filename='',
commit_msg='',
commit_sha='',
prepare_commit_message_source='',
commit_object_name='',
checkout_type='',
is_squash_merge='',
rewrite_command='',
Expand All @@ -99,8 +99,8 @@ def run_opts(
hook_stage=hook_stage,
show_diff_on_failure=show_diff_on_failure,
commit_msg_filename=commit_msg_filename,
commit_msg=commit_msg,
commit_sha=commit_sha,
prepare_commit_message_source=prepare_commit_message_source,
commit_object_name=commit_object_name,
checkout_type=checkout_type,
is_squash_merge=is_squash_merge,
rewrite_command=rewrite_command,
Expand Down

0 comments on commit e3f2c88

Please sign in to comment.