mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
The remote branch reference was exposed as an environment variable for a pre-push hook, which makes decisions on git pushes to a particular remote branch name pattern.
This commit is contained in:
parent
a062cbd439
commit
945549acbc
3 changed files with 13 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
@ -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,
|
||||
|
|
@ -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:
|
||||
|
|
@ -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}^')
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -371,6 +371,11 @@ def run(
|
|||
environ['PRE_COMMIT_FROM_REF'] = args.from_ref
|
||||
environ['PRE_COMMIT_TO_REF'] = args.to_ref
|
||||
|
||||
# Exposes remote branch ref as an environment variable
|
||||
# for pre-push hooks consumption
|
||||
if args.remote_branch:
|
||||
environ['PRE_COMMIT_REMOTE_REF'] = args.remote_branch
|
||||
|
||||
if args.remote_name and args.remote_url:
|
||||
environ['PRE_COMMIT_REMOTE_NAME'] = args.remote_name
|
||||
environ['PRE_COMMIT_REMOTE_URL'] = args.remote_url
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ def run_opts(
|
|||
color=False,
|
||||
verbose=False,
|
||||
hook=None,
|
||||
remote_branch='',
|
||||
from_ref='',
|
||||
to_ref='',
|
||||
remote_name='',
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue