Adding upstream version 2.14.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
af2c814963
commit
dcfd04081c
15 changed files with 148 additions and 56 deletions
|
@ -70,6 +70,7 @@ def _ns(
|
|||
*,
|
||||
all_files: bool = False,
|
||||
remote_branch: Optional[str] = None,
|
||||
local_branch: Optional[str] = None,
|
||||
from_ref: Optional[str] = None,
|
||||
to_ref: Optional[str] = None,
|
||||
remote_name: Optional[str] = None,
|
||||
|
@ -82,6 +83,7 @@ def _ns(
|
|||
color=color,
|
||||
hook_stage=hook_type.replace('pre-', ''),
|
||||
remote_branch=remote_branch,
|
||||
local_branch=local_branch,
|
||||
from_ref=from_ref,
|
||||
to_ref=to_ref,
|
||||
remote_name=remote_name,
|
||||
|
@ -110,7 +112,7 @@ def _pre_push_ns(
|
|||
remote_url = args[1]
|
||||
|
||||
for line in stdin.decode().splitlines():
|
||||
_, local_sha, remote_branch, remote_sha = line.split()
|
||||
local_branch, local_sha, remote_branch, remote_sha = line.split()
|
||||
if local_sha == Z40:
|
||||
continue
|
||||
elif remote_sha != Z40 and _rev_exists(remote_sha):
|
||||
|
@ -118,6 +120,7 @@ def _pre_push_ns(
|
|||
'pre-push', color,
|
||||
from_ref=remote_sha, to_ref=local_sha,
|
||||
remote_branch=remote_branch,
|
||||
local_branch=local_branch,
|
||||
remote_name=remote_name, remote_url=remote_url,
|
||||
)
|
||||
else:
|
||||
|
@ -139,6 +142,7 @@ def _pre_push_ns(
|
|||
all_files=True,
|
||||
remote_name=remote_name, remote_url=remote_url,
|
||||
remote_branch=remote_branch,
|
||||
local_branch=local_branch,
|
||||
)
|
||||
else:
|
||||
rev_cmd = ('git', 'rev-parse', f'{first_ancestor}^')
|
||||
|
@ -148,6 +152,7 @@ def _pre_push_ns(
|
|||
from_ref=source, to_ref=local_sha,
|
||||
remote_name=remote_name, remote_url=remote_url,
|
||||
remote_branch=remote_branch,
|
||||
local_branch=local_branch,
|
||||
)
|
||||
|
||||
# nothing to push
|
||||
|
|
|
@ -21,13 +21,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
# This is used to identify the hook file we install
|
||||
PRIOR_HASHES = (
|
||||
'4d9958c90bc262f47553e2c073f14cfe',
|
||||
'd8ee923c46731b42cd95cc869add4062',
|
||||
'49fd668cb42069aa1b6048464be5d395',
|
||||
'79f09a650522a87b0da915d0d983b2de',
|
||||
'e358c9dae00eac5d06b38dfdb1e33a8c',
|
||||
b'4d9958c90bc262f47553e2c073f14cfe',
|
||||
b'd8ee923c46731b42cd95cc869add4062',
|
||||
b'49fd668cb42069aa1b6048464be5d395',
|
||||
b'79f09a650522a87b0da915d0d983b2de',
|
||||
b'e358c9dae00eac5d06b38dfdb1e33a8c',
|
||||
)
|
||||
CURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'
|
||||
CURRENT_HASH = b'138fd403232d2ddd5efb44317e38bf03'
|
||||
TEMPLATE_START = '# start templated\n'
|
||||
TEMPLATE_END = '# end templated\n'
|
||||
# Homebrew/homebrew-core#35825: be more timid about appropriate `PATH`
|
||||
|
@ -48,7 +48,7 @@ def _hook_paths(
|
|||
def is_our_script(filename: str) -> bool:
|
||||
if not os.path.exists(filename): # pragma: win32 no cover (symlink)
|
||||
return False
|
||||
with open(filename) as f:
|
||||
with open(filename, 'rb') as f:
|
||||
contents = f.read()
|
||||
return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
|
||||
|
||||
|
|
|
@ -371,7 +371,11 @@ def run(
|
|||
environ['PRE_COMMIT_FROM_REF'] = args.from_ref
|
||||
environ['PRE_COMMIT_TO_REF'] = args.to_ref
|
||||
|
||||
if args.remote_name and args.remote_url and args.remote_branch:
|
||||
if (
|
||||
args.remote_name and args.remote_url and
|
||||
args.remote_branch and args.local_branch
|
||||
):
|
||||
environ['PRE_COMMIT_LOCAL_BRANCH'] = args.local_branch
|
||||
environ['PRE_COMMIT_REMOTE_BRANCH'] = args.remote_branch
|
||||
environ['PRE_COMMIT_REMOTE_NAME'] = args.remote_name
|
||||
environ['PRE_COMMIT_REMOTE_URL'] = args.remote_url
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from typing import Sequence
|
||||
from typing import Tuple
|
||||
|
||||
|
@ -9,6 +8,7 @@ import pre_commit.constants as C
|
|||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.prefix import Prefix
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output_b
|
||||
|
||||
|
@ -26,12 +26,28 @@ def _is_in_docker() -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _get_container_id() -> str:
|
||||
# It's assumed that we already check /proc/1/cgroup in _is_in_docker. The
|
||||
# cpuset cgroup controller existed since cgroups were introduced so this
|
||||
# way of getting the container ID is pretty reliable.
|
||||
with open('/proc/1/cgroup', 'rb') as f:
|
||||
for line in f.readlines():
|
||||
if line.split(b':')[1] == b'cpuset':
|
||||
return os.path.basename(line.split(b':')[2]).strip().decode()
|
||||
raise RuntimeError('Failed to find the container ID in /proc/1/cgroup.')
|
||||
|
||||
|
||||
def _get_docker_path(path: str) -> str:
|
||||
if not _is_in_docker():
|
||||
return path
|
||||
hostname = socket.gethostname()
|
||||
|
||||
_, out, _ = cmd_output_b('docker', 'inspect', hostname)
|
||||
container_id = _get_container_id()
|
||||
|
||||
try:
|
||||
_, out, _ = cmd_output_b('docker', 'inspect', container_id)
|
||||
except CalledProcessError:
|
||||
# self-container was not visible from here (perhaps docker-in-docker)
|
||||
return path
|
||||
|
||||
container, = json.loads(out)
|
||||
for mount in container['Mounts']:
|
||||
|
|
|
@ -99,6 +99,9 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
|
|||
parser.add_argument(
|
||||
'--remote-branch', help='Remote branch ref used by `git push`.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--local-branch', help='Local branch ref used by `git push`.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--from-ref', '--source', '-s',
|
||||
help=(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue