mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix #238 : pre-commit autoupdate fails with local hooks
This commit is contained in:
parent
1c46446427
commit
b575cb510c
5 changed files with 30 additions and 14 deletions
|
|
@ -8,6 +8,7 @@ from aspy.yaml import ordered_load
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||||
|
from pre_commit.clientlib.validate_config import is_local_hooks
|
||||||
from pre_commit.clientlib.validate_config import load_config
|
from pre_commit.clientlib.validate_config import load_config
|
||||||
from pre_commit.jsonschema_extensions import remove_defaults
|
from pre_commit.jsonschema_extensions import remove_defaults
|
||||||
from pre_commit.ordereddict import OrderedDict
|
from pre_commit.ordereddict import OrderedDict
|
||||||
|
|
@ -67,6 +68,8 @@ def autoupdate(runner):
|
||||||
)
|
)
|
||||||
|
|
||||||
for repo_config in input_configs:
|
for repo_config in input_configs:
|
||||||
|
if is_local_hooks(repo_config):
|
||||||
|
continue
|
||||||
sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
|
sys.stdout.write('Updating {0}...'.format(repo_config['repo']))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -125,9 +125,8 @@ class Repository(object):
|
||||||
|
|
||||||
|
|
||||||
class LocalRepository(Repository):
|
class LocalRepository(Repository):
|
||||||
def __init__(self, repo_config, repo_path_getter=None):
|
def __init__(self, repo_config):
|
||||||
repo_path_getter = None
|
super(LocalRepository, self).__init__(repo_config, None)
|
||||||
super(LocalRepository, self).__init__(repo_config, repo_path_getter)
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def hooks(self):
|
def hooks(self):
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,19 @@ def make_repo(tmpdir_factory, repo_source):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def config_with_local_hooks():
|
||||||
|
return OrderedDict((
|
||||||
|
('repo', 'local'),
|
||||||
|
('hooks', [OrderedDict((
|
||||||
|
('id', 'do_not_commit'),
|
||||||
|
('name', 'Block if "DO NOT COMMIT" is found'),
|
||||||
|
('entry', 'DO NOT COMMIT'),
|
||||||
|
('language', 'pcre'),
|
||||||
|
('files', '^(.*)$'),
|
||||||
|
))])
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
|
def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
|
||||||
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||||
config = OrderedDict((
|
config = OrderedDict((
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ from pre_commit.runner import Runner
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.util import cwd
|
from pre_commit.util import cwd
|
||||||
from testing.auto_namedtuple import auto_namedtuple
|
from testing.auto_namedtuple import auto_namedtuple
|
||||||
|
from testing.fixtures import add_config_to_repo
|
||||||
|
from testing.fixtures import config_with_local_hooks
|
||||||
|
from testing.fixtures import git_dir
|
||||||
from testing.fixtures import make_config_from_repo
|
from testing.fixtures import make_config_from_repo
|
||||||
from testing.fixtures import make_repo
|
from testing.fixtures import make_repo
|
||||||
from testing.fixtures import write_config
|
from testing.fixtures import write_config
|
||||||
|
|
@ -137,3 +140,10 @@ def test_autoupdate_hook_disappearing_repo(
|
||||||
after = open(C.CONFIG_FILE).read()
|
after = open(C.CONFIG_FILE).read()
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert before == after
|
assert before == after
|
||||||
|
|
||||||
|
|
||||||
|
def test_autoupdate_local_hooks(tmpdir_factory):
|
||||||
|
git_path = git_dir(tmpdir_factory)
|
||||||
|
config = config_with_local_hooks()
|
||||||
|
path = add_config_to_repo(git_path, config)
|
||||||
|
assert autoupdate(Runner(path)) == 0
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||||
from pre_commit.jsonschema_extensions import apply_defaults
|
from pre_commit.jsonschema_extensions import apply_defaults
|
||||||
from pre_commit.languages.python import PythonEnv
|
from pre_commit.languages.python import PythonEnv
|
||||||
from pre_commit.ordereddict import OrderedDict
|
|
||||||
from pre_commit.repository import Repository
|
from pre_commit.repository import Repository
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.util import cwd
|
from pre_commit.util import cwd
|
||||||
|
from testing.fixtures import config_with_local_hooks
|
||||||
from testing.fixtures import git_dir
|
from testing.fixtures import git_dir
|
||||||
from testing.fixtures import make_config_from_repo
|
from testing.fixtures import make_config_from_repo
|
||||||
from testing.fixtures import make_repo
|
from testing.fixtures import make_repo
|
||||||
|
|
@ -404,16 +404,7 @@ def test_tags_on_repositories(in_tmpdir, tmpdir_factory, store):
|
||||||
|
|
||||||
|
|
||||||
def test_local_repository():
|
def test_local_repository():
|
||||||
config = OrderedDict((
|
config = config_with_local_hooks()
|
||||||
('repo', 'local'),
|
|
||||||
('hooks', [OrderedDict((
|
|
||||||
('id', 'do_not_commit'),
|
|
||||||
('name', 'Block if "DO NOT COMMIT" is found'),
|
|
||||||
('entry', 'DO NOT COMMIT'),
|
|
||||||
('language', 'pcre'),
|
|
||||||
('files', '^(.*)$'),
|
|
||||||
))])
|
|
||||||
))
|
|
||||||
local_repo = Repository.create(config, 'dummy')
|
local_repo = Repository.create(config, 'dummy')
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
local_repo.sha
|
local_repo.sha
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue