mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-27 11:28:59 -06:00
Push remote env var details
This commit is contained in:
committed by
Anthony Sottile
parent
b66d28964b
commit
57cc814b8b
@@ -312,6 +312,10 @@ def run(
|
||||
environ['PRE_COMMIT_ORIGIN'] = args.origin
|
||||
environ['PRE_COMMIT_SOURCE'] = args.source
|
||||
|
||||
if args.push_remote_name and args.push_remote_url:
|
||||
environ['PRE_COMMIT_REMOTE_NAME'] = args.push_remote_name
|
||||
environ['PRE_COMMIT_REMOTE_URL'] = args.push_remote_url
|
||||
|
||||
with contextlib.ExitStack() as exit_stack:
|
||||
if stash:
|
||||
exit_stack.enter_context(staged_files_only(store.directory))
|
||||
|
||||
@@ -101,6 +101,12 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
||||
'--commit-msg-filename',
|
||||
help='Filename to check when running during `commit-msg`',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--push-remote-name', help='Remote name used by `git push`.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--push-remote-url', help='Remote url used by `git push`.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hook-stage', choices=C.STAGES, default='commit',
|
||||
help='The stage during which the hook is fired. One of %(choices)s',
|
||||
|
||||
@@ -120,7 +120,8 @@ def _rev_exists(rev: str) -> bool:
|
||||
|
||||
|
||||
def _pre_push(stdin: bytes) -> Tuple[str, ...]:
|
||||
remote = sys.argv[1]
|
||||
remote_name = sys.argv[1]
|
||||
remote_url = sys.argv[2]
|
||||
|
||||
opts: Tuple[str, ...] = ()
|
||||
for line in stdin.decode().splitlines():
|
||||
@@ -133,7 +134,7 @@ def _pre_push(stdin: bytes) -> Tuple[str, ...]:
|
||||
# ancestors not found in remote
|
||||
ancestors = subprocess.check_output((
|
||||
'git', 'rev-list', local_sha, '--topo-order', '--reverse',
|
||||
'--not', f'--remotes={remote}',
|
||||
'--not', f'--remotes={remote_name}',
|
||||
)).decode().strip()
|
||||
if not ancestors:
|
||||
continue
|
||||
@@ -150,7 +151,10 @@ def _pre_push(stdin: bytes) -> Tuple[str, ...]:
|
||||
opts = ('--origin', local_sha, '--source', source)
|
||||
|
||||
if opts:
|
||||
return opts
|
||||
remote_opts = (
|
||||
'--push-remote-name', remote_name, '--push-remote-url', remote_url,
|
||||
)
|
||||
return opts + remote_opts
|
||||
else:
|
||||
# An attempt to push an empty changeset
|
||||
raise EarlyExit()
|
||||
|
||||
Reference in New Issue
Block a user