mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add pre-commit try-repo
`try-repo` is useful for: - Trying out a remote hook repository without needing to configure it. - Testing a hook repository while developing it.
This commit is contained in:
parent
e8641ee0a3
commit
2c88791a7f
15 changed files with 254 additions and 110 deletions
|
|
@ -10,6 +10,7 @@ from aspy.yaml import ordered_dump
|
|||
from aspy.yaml import ordered_load
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import git
|
||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||
from pre_commit.clientlib import load_manifest
|
||||
from pre_commit.schema import apply_defaults
|
||||
|
|
@ -17,7 +18,6 @@ from pre_commit.schema import validate
|
|||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import copy_tree_to_path
|
||||
from pre_commit.util import cwd
|
||||
from testing.util import get_head_sha
|
||||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
|
|||
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||
config = OrderedDict((
|
||||
('repo', 'file://{}'.format(repo_path)),
|
||||
('sha', sha or get_head_sha(repo_path)),
|
||||
('sha', sha or git.head_sha(repo_path)),
|
||||
(
|
||||
'hooks',
|
||||
hooks or [OrderedDict((('id', hook['id']),)) for hook in manifest],
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from pre_commit import parse_shebang
|
|||
from pre_commit.languages.docker import docker_is_running
|
||||
from pre_commit.languages.pcre import GREP
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
|
||||
|
||||
TESTING_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
|
@ -18,11 +18,6 @@ def get_resource_path(path):
|
|||
return os.path.join(TESTING_DIR, 'resources', path)
|
||||
|
||||
|
||||
def get_head_sha(dir):
|
||||
with cwd(dir):
|
||||
return cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
|
||||
|
||||
|
||||
def cmd_output_mocked_pre_commit_home(*args, **kwargs):
|
||||
# keyword-only argument
|
||||
tempdir_factory = kwargs.pop('tempdir_factory')
|
||||
|
|
@ -72,3 +67,31 @@ xfailif_no_symlink = pytest.mark.xfail(
|
|||
not hasattr(os, 'symlink'),
|
||||
reason='Symlink is not supported on this platform',
|
||||
)
|
||||
|
||||
|
||||
def run_opts(
|
||||
all_files=False,
|
||||
files=(),
|
||||
color=False,
|
||||
verbose=False,
|
||||
hook=None,
|
||||
origin='',
|
||||
source='',
|
||||
hook_stage='commit',
|
||||
show_diff_on_failure=False,
|
||||
commit_msg_filename='',
|
||||
):
|
||||
# These are mutually exclusive
|
||||
assert not (all_files and files)
|
||||
return auto_namedtuple(
|
||||
all_files=all_files,
|
||||
files=files,
|
||||
color=color,
|
||||
verbose=verbose,
|
||||
hook=hook,
|
||||
origin=origin,
|
||||
source=source,
|
||||
hook_stage=hook_stage,
|
||||
show_diff_on_failure=show_diff_on_failure,
|
||||
commit_msg_filename=commit_msg_filename,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue