Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ repos:
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

7 changes: 6 additions & 1 deletion pre_commit/commands/hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _ns(
color: bool,
*,
all_files: bool = False,
remote_branch: Optional[str] = None,
from_ref: Optional[str] = None,
to_ref: Optional[str] = None,
remote_name: Optional[str] = None,
Expand All @@ -79,6 +80,7 @@ def _ns(
return argparse.Namespace(
color=color,
hook_stage=hook_type.replace('pre-', ''),
remote_branch=remote_branch,
from_ref=from_ref,
to_ref=to_ref,
remote_name=remote_name,
Expand Down Expand Up @@ -106,13 +108,14 @@ def _pre_push_ns(
remote_url = args[1]

for line in stdin.decode().splitlines():
_, local_sha, _, remote_sha = line.split()
_, local_sha, remote_branch, remote_sha = line.split()
if local_sha == Z40:
continue
elif remote_sha != Z40 and _rev_exists(remote_sha):
return _ns(
'pre-push', color,
from_ref=remote_sha, to_ref=local_sha,
remote_branch=remote_branch,
remote_name=remote_name, remote_url=remote_url,
)
else:
Expand All @@ -133,6 +136,7 @@ def _pre_push_ns(
'pre-push', color,
all_files=True,
remote_name=remote_name, remote_url=remote_url,
remote_branch=remote_branch,
)
else:
rev_cmd = ('git', 'rev-parse', f'{first_ancestor}^')
Expand All @@ -141,6 +145,7 @@ def _pre_push_ns(
'pre-push', color,
from_ref=source, to_ref=local_sha,
remote_name=remote_name, remote_url=remote_url,
remote_branch=remote_branch,
)

# nothing to push
Expand Down
3 changes: 2 additions & 1 deletion pre_commit/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ def run(
environ['PRE_COMMIT_FROM_REF'] = args.from_ref
environ['PRE_COMMIT_TO_REF'] = args.to_ref

if args.remote_name and args.remote_url:
if args.remote_name and args.remote_url and args.remote_branch:
environ['PRE_COMMIT_REMOTE_BRANCH'] = args.remote_branch
environ['PRE_COMMIT_REMOTE_NAME'] = args.remote_name
environ['PRE_COMMIT_REMOTE_URL'] = args.remote_url

Expand Down
3 changes: 3 additions & 0 deletions pre_commit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
'--hook-stage', choices=C.STAGES, default='commit',
help='The stage during which the hook is fired. One of %(choices)s',
)
parser.add_argument(
'--remote-branch', help='Remote branch ref used by `git push`.',
)
parser.add_argument(
'--from-ref', '--source', '-s',
help=(
Expand Down
2 changes: 2 additions & 0 deletions testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def run_opts(
color=False,
verbose=False,
hook=None,
remote_branch='',
from_ref='',
to_ref='',
remote_name='',
Expand All @@ -78,6 +79,7 @@ def run_opts(
color=color,
verbose=verbose,
hook=hook,
remote_branch=remote_branch,
from_ref=from_ref,
to_ref=to_ref,
remote_name=remote_name,
Expand Down
1 change: 1 addition & 0 deletions tests/commands/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def test_from_ref_to_ref_error_msg_error(
def test_all_push_options_ok(cap_out, store, repo_with_passing_hook):
args = run_opts(
from_ref='master', to_ref='master',
remote_branch='master',
remote_name='origin', remote_url='https://example.com/repo',
)
ret, printed = _do_run(cap_out, store, repo_with_passing_hook, args)
Expand Down