Push remote env var details · precommit/pre-commit@57cc814 · GitHub
Skip to content

Commit 57cc814

Browse files
David Martinez Barreiroasottile
authored andcommitted
Push remote env var details
1 parent b66d289 commit 57cc814

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

pre_commit/commands/run.py

Lines changed: 4 additions & 0 deletions

pre_commit/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
101101
'--commit-msg-filename',
102102
help='Filename to check when running during `commit-msg`',
103103
)
104+
parser.add_argument(
105+
'--push-remote-name', help='Remote name used by `git push`.',
106+
)
107+
parser.add_argument(
108+
'--push-remote-url', help='Remote url used by `git push`.',
109+
)
104110
parser.add_argument(
105111
'--hook-stage', choices=C.STAGES, default='commit',
106112
help='The stage during which the hook is fired. One of %(choices)s',

pre_commit/resources/hook-tmpl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def _rev_exists(rev: str) -> bool:
120120

121121

122122
def _pre_push(stdin: bytes) -> Tuple[str, ...]:
123-
remote = sys.argv[1]
123+
remote_name = sys.argv[1]
124+
remote_url = sys.argv[2]
124125

125126
opts: Tuple[str, ...] = ()
126127
for line in stdin.decode().splitlines():
@@ -133,7 +134,7 @@ def _pre_push(stdin: bytes) -> Tuple[str, ...]:
133134
# ancestors not found in remote
134135
ancestors = subprocess.check_output((
135136
'git', 'rev-list', local_sha, '--topo-order', '--reverse',
136-
'--not', f'--remotes={remote}',
137+
'--not', f'--remotes={remote_name}',
137138
)).decode().strip()
138139
if not ancestors:
139140
continue
@@ -150,7 +151,10 @@ def _pre_push(stdin: bytes) -> Tuple[str, ...]:
150151
opts = ('--origin', local_sha, '--source', source)
151152

152153
if opts:
153-
return opts
154+
remote_opts = (
155+
'--push-remote-name', remote_name, '--push-remote-url', remote_url,
156+
)
157+
return opts + remote_opts
154158
else:
155159
# An attempt to push an empty changeset
156160
raise EarlyExit()

testing/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def run_opts(
6767
hook=None,
6868
origin='',
6969
source='',
70+
push_remote_name='',
71+
push_remote_url='',
7072
hook_stage='commit',
7173
show_diff_on_failure=False,
7274
commit_msg_filename='',
@@ -81,6 +83,8 @@ def run_opts(
8183
hook=hook,
8284
origin=origin,
8385
source=source,
86+
push_remote_name=push_remote_name,
87+
push_remote_url=push_remote_url,
8488
hook_stage=hook_stage,
8589
show_diff_on_failure=show_diff_on_failure,
8690
commit_msg_filename=commit_msg_filename,

tests/commands/run_test.py

Lines changed: 29 additions & 0 deletions

0 commit comments

Comments
 (0)