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

‎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

0 commit comments

Comments
 (0)