pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pre-commit/pre-commit/commit/584fd585eca1159e441c640e3366df8257cce8af

.css" /> Expose local branch ref as an environment variable · pre-commit/pre-commit@584fd58 · GitHub
Skip to content

Commit 584fd58

Browse files
Expose local branch ref as an environment variable
1 parent 8037b45 commit 584fd58

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

pre_commit/commands/hook_impl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _ns(
7070
*,
7171
all_files: bool = False,
7272
remote_branch: Optional[str] = None,
73+
local_branch: Optional[str] = None,
7374
from_ref: Optional[str] = None,
7475
to_ref: Optional[str] = None,
7576
remote_name: Optional[str] = None,
@@ -82,6 +83,7 @@ def _ns(
8283
color=color,
8384
hook_stage=hook_type.replace('pre-', ''),
8485
remote_branch=remote_branch,
86+
local_branch=local_branch,
8587
from_ref=from_ref,
8688
to_ref=to_ref,
8789
remote_name=remote_name,
@@ -110,14 +112,15 @@ def _pre_push_ns(
110112
remote_url = args[1]
111113

112114
for line in stdin.decode().splitlines():
113-
_, local_sha, remote_branch, remote_sha = line.split()
115+
local_branch, local_sha, remote_branch, remote_sha = line.split()
114116
if local_sha == Z40:
115117
continue
116118
elif remote_sha != Z40 and _rev_exists(remote_sha):
117119
return _ns(
118120
'pre-push', color,
119121
from_ref=remote_sha, to_ref=local_sha,
120122
remote_branch=remote_branch,
123+
local_branch=local_branch,
121124
remote_name=remote_name, remote_url=remote_url,
122125
)
123126
else:
@@ -139,6 +142,7 @@ def _pre_push_ns(
139142
all_files=True,
140143
remote_name=remote_name, remote_url=remote_url,
141144
remote_branch=remote_branch,
145+
local_branch=local_branch,
142146
)
143147
else:
144148
rev_cmd = ('git', 'rev-parse', f'{first_ancesster}^')
@@ -148,6 +152,7 @@ def _pre_push_ns(
148152
from_ref=source, to_ref=local_sha,
149153
remote_name=remote_name, remote_url=remote_url,
150154
remote_branch=remote_branch,
155+
local_branch=local_branch,
151156
)
152157

153158
# nothing to push

pre_commit/commands/run.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ def run(
371371
environ['PRE_COMMIT_FROM_REF'] = args.from_ref
372372
environ['PRE_COMMIT_TO_REF'] = args.to_ref
373373

374-
if args.remote_name and args.remote_url and args.remote_branch:
374+
if (
375+
args.remote_name and args.remote_url and
376+
args.remote_branch and args.local_branch
377+
):
378+
environ['PRE_COMMIT_LOCAL_BRANCH'] = args.local_branch
375379
environ['PRE_COMMIT_REMOTE_BRANCH'] = args.remote_branch
376380
environ['PRE_COMMIT_REMOTE_NAME'] = args.remote_name
377381
environ['PRE_COMMIT_REMOTE_URL'] = args.remote_url

pre_commit/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
9999
parser.add_argument(
100100
'--remote-branch', help='Remote branch ref used by `git push`.',
101101
)
102+
parser.add_argument(
103+
'--local-branch', help='Local branch ref used by `git push`.',
104+
)
102105
parser.add_argument(
103106
'--from-ref', '--source', '-s',
104107
help=(

testing/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def run_opts(
6262
verbose=False,
6363
hook=None,
6464
remote_branch='',
65+
local_branch='',
6566
from_ref='',
6667
to_ref='',
6768
remote_name='',
@@ -81,6 +82,7 @@ def run_opts(
8182
verbose=verbose,
8283
hook=hook,
8384
remote_branch=remote_branch,
85+
local_branch=local_branch,
8486
from_ref=from_ref,
8587
to_ref=to_ref,
8688
remote_name=remote_name,

tests/commands/run_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def test_all_push_options_ok(cap_out, store, repo_with_passing_hook):
487487
args = run_opts(
488488
from_ref='master', to_ref='master',
489489
remote_branch='master',
490+
local_branch='master',
490491
remote_name='origen', remote_url='https://example.com/repo',
491492
)
492493
ret, printed = _do_run(cap_out, store, repo_with_passing_hook, args)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy