Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 378dbb9

Browse files
author
Morgan Hein
committed
feat: enable skip-sha-check to bypass rebasing issues
1 parent 9c7ea88 commit 378dbb9

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

pre_commit/clientlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ def check(self, dct: dict[str, Any]) -> None:
517517
cfgv.Optional('files', check_string_regex, ''),
518518
cfgv.Optional('exclude', check_string_regex, '^$'),
519519
cfgv.Optional('fail_fast', cfgv.check_bool, False),
520+
cfgv.Optional('skip-remote-sha-check', cfgv.check_bool, False),
520521
cfgv.WarnAdditionalKeys(
521522
(
522523
'repos',
@@ -528,6 +529,7 @@ def check(self, dct: dict[str, Any]) -> None:
528529
'fail_fast',
529530
'minimum_pre_commit_version',
530531
'ci',
532+
'skip-remote-sha-check',
531533
),
532534
warn_unknown_keys_root,
533535
),

pre_commit/commands/hook_impl.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
from __future__ import annotations
22

33
import argparse
4+
import logging
45
import os.path
56
import subprocess
67
import sys
78
from collections.abc import Sequence
89

10+
from pre_commit.clientlib import load_config
911
from pre_commit.commands.run import run
1012
from pre_commit.envcontext import envcontext
1113
from pre_commit.parse_shebang import normalize_cmd
1214
from pre_commit.store import Store
1315

16+
logger = logging.getLogger('pre_commit')
17+
1418
Z40 = '0' * 40
1519

1620

@@ -118,6 +122,7 @@ def _pre_push_ns(
118122
color: bool,
119123
args: Sequence[str],
120124
stdin: bytes,
125+
skip_remote_sha_check: bool = False,
121126
) -> argparse.Namespace | None:
122127
remote_name = args[0]
123128
remote_url = args[1]
@@ -127,7 +132,7 @@ def _pre_push_ns(
127132
local_branch, local_sha, remote_branch, remote_sha = parts
128133
if local_sha == Z40:
129134
continue
130-
elif remote_sha != Z40 and _rev_exists(remote_sha):
135+
elif not skip_remote_sha_check and remote_sha != Z40 and _rev_exists(remote_sha):
131136
return _ns(
132137
'pre-push', color,
133138
from_ref=remote_sha, to_ref=local_sha,
@@ -213,10 +218,11 @@ def _run_ns(
213218
color: bool,
214219
args: Sequence[str],
215220
stdin: bytes,
221+
skip_remote_sha_check: bool = False,
216222
) -> argparse.Namespace | None:
217223
_check_args_length(hook_type, args)
218224
if hook_type == 'pre-push':
219-
return _pre_push_ns(color, args, stdin)
225+
return _pre_push_ns(color, args, stdin, skip_remote_sha_check)
220226
elif hook_type in 'commit-msg':
221227
return _ns(hook_type, color, commit_msg_filename=args[0])
222228
elif hook_type == 'prepare-commit-msg' and len(args) == 1:
@@ -265,7 +271,20 @@ def hook_impl(
265271
) -> int:
266272
retv, stdin = _run_legacy(hook_type, hook_dir, args)
267273
_validate_config(retv, config, skip_on_missing_config)
268-
ns = _run_ns(hook_type, color, args, stdin)
274+
275+
# Load config to get skip-remote-sha-check setting (only for pre-push)
276+
skip_remote_sha_check = False
277+
if hook_type == 'pre-push':
278+
try:
279+
cfg = load_config(config)
280+
skip_remote_sha_check = cfg.get('skip-remote-sha-check', False)
281+
if skip_remote_sha_check:
282+
logger.info('skip-remote-sha-check is enabled')
283+
except Exception:
284+
# If config loading fails, use safe default (False)
285+
skip_remote_sha_check = False
286+
287+
ns = _run_ns(hook_type, color, args, stdin, skip_remote_sha_check)
269288
if ns is None:
270289
return retv
271290
else:

0 commit comments

Comments
 (0)