mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
commit
44330fbec8
5 changed files with 48 additions and 13 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
- id: name-tests-test
|
- id: name-tests-test
|
||||||
- id: flake8
|
- id: flake8
|
||||||
- repo: git@github.com:pre-commit/pre-commit
|
- repo: git@github.com:pre-commit/pre-commit
|
||||||
sha: 96174deac671b451ee2a3fbdc647ad9606415e15
|
sha: bcb1283267c0a041c77150a80a58f1bc2a3252d6
|
||||||
hooks:
|
hooks:
|
||||||
- id: validate_config
|
- id: validate_config
|
||||||
- id: validate_manifest
|
- id: validate_manifest
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from plumbum import local
|
||||||
|
|
||||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||||
from pre_commit.util import clean_path_on_failure
|
from pre_commit.util import clean_path_on_failure
|
||||||
|
from pre_commit.util import hex_md5
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('pre_commit')
|
logger = logging.getLogger('pre_commit')
|
||||||
|
|
@ -74,7 +75,7 @@ class Store(object):
|
||||||
self.require_created()
|
self.require_created()
|
||||||
|
|
||||||
# Check if we already exist
|
# Check if we already exist
|
||||||
sha_path = os.path.join(self.directory, sha)
|
sha_path = os.path.join(self.directory, sha + '_' + hex_md5(url))
|
||||||
if os.path.exists(sha_path):
|
if os.path.exists(sha_path):
|
||||||
return os.readlink(sha_path)
|
return os.readlink(sha_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -56,3 +57,11 @@ def noop_context():
|
||||||
|
|
||||||
def shell_escape(arg):
|
def shell_escape(arg):
|
||||||
return "'" + arg.replace("'", "'\"'\"'".strip()) + "'"
|
return "'" + arg.replace("'", "'\"'\"'".strip()) + "'"
|
||||||
|
|
||||||
|
|
||||||
|
def hex_md5(s):
|
||||||
|
"""Hexdigest an md5 of the string.
|
||||||
|
|
||||||
|
:param text s:
|
||||||
|
"""
|
||||||
|
return hashlib.md5(s.encode('utf-8')).hexdigest()
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,6 @@ from testing.fixtures import make_repo
|
||||||
from testing.util import skipif_slowtests_false
|
from testing.util import skipif_slowtests_false
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
|
||||||
def test_install_python_repo_in_env(tmpdir_factory, store):
|
|
||||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
|
||||||
config = make_config_from_repo(path)
|
|
||||||
repo = Repository.create(config, store)
|
|
||||||
repo.install()
|
|
||||||
assert os.path.exists(os.path.join(store.directory, repo.sha, 'py_env'))
|
|
||||||
|
|
||||||
|
|
||||||
def _test_hook_repo(
|
def _test_hook_repo(
|
||||||
tmpdir_factory,
|
tmpdir_factory,
|
||||||
store,
|
store,
|
||||||
|
|
@ -265,3 +256,33 @@ def test_config_overrides_repo_specifics(tmpdir_factory, store):
|
||||||
config['hooks'][0]['files'] = '\\.sh$'
|
config['hooks'][0]['files'] = '\\.sh$'
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
assert repo.hooks['bash_hook']['files'] == '\\.sh$'
|
assert repo.hooks['bash_hook']['files'] == '\\.sh$'
|
||||||
|
|
||||||
|
|
||||||
|
def _create_repo_with_tags(tmpdir_factory, src, tag):
|
||||||
|
path = make_repo(tmpdir_factory, src)
|
||||||
|
with local.cwd(path):
|
||||||
|
local['git']('tag', tag)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_tags_on_repositories(in_tmpdir, tmpdir_factory, store):
|
||||||
|
tag = 'v1.1'
|
||||||
|
git_dir_1 = _create_repo_with_tags(tmpdir_factory, 'prints_cwd_repo', tag)
|
||||||
|
git_dir_2 = _create_repo_with_tags(
|
||||||
|
tmpdir_factory, 'script_hooks_repo', tag,
|
||||||
|
)
|
||||||
|
|
||||||
|
repo_1 = Repository.create(
|
||||||
|
make_config_from_repo(git_dir_1, sha=tag), store,
|
||||||
|
)
|
||||||
|
ret = repo_1.run_hook('prints_cwd', [])
|
||||||
|
assert ret[0] == 0
|
||||||
|
assert ret[1].strip() == in_tmpdir
|
||||||
|
|
||||||
|
repo_2 = Repository.create(
|
||||||
|
make_config_from_repo(git_dir_2, sha=tag), store,
|
||||||
|
)
|
||||||
|
ret = repo_2.run_hook('bash_hook', ['bar'])
|
||||||
|
assert ret[0] == 0
|
||||||
|
assert ret[1] == 'bar\nHello World\n'
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from pre_commit import five
|
||||||
from pre_commit.store import _get_default_directory
|
from pre_commit.store import _get_default_directory
|
||||||
from pre_commit.store import logger
|
from pre_commit.store import logger
|
||||||
from pre_commit.store import Store
|
from pre_commit.store import Store
|
||||||
|
from pre_commit.util import hex_md5
|
||||||
from testing.fixtures import git_dir
|
from testing.fixtures import git_dir
|
||||||
from testing.util import get_head_sha
|
from testing.util import get_head_sha
|
||||||
|
|
||||||
|
|
@ -104,7 +105,7 @@ def test_clone(store, tmpdir_factory, log_info_mock):
|
||||||
assert get_head_sha(ret) == sha
|
assert get_head_sha(ret) == sha
|
||||||
|
|
||||||
# Assert that we made a symlink from the sha to the repo
|
# Assert that we made a symlink from the sha to the repo
|
||||||
sha_path = os.path.join(store.directory, sha)
|
sha_path = os.path.join(store.directory, sha + '_' + hex_md5(path))
|
||||||
assert os.path.exists(sha_path)
|
assert os.path.exists(sha_path)
|
||||||
assert os.path.islink(sha_path)
|
assert os.path.islink(sha_path)
|
||||||
assert os.readlink(sha_path) == ret
|
assert os.readlink(sha_path) == ret
|
||||||
|
|
@ -136,7 +137,10 @@ def test_clone_when_repo_already_exists(store):
|
||||||
store.require_created()
|
store.require_created()
|
||||||
repo_dir_path = os.path.join(store.directory, 'repo_dir')
|
repo_dir_path = os.path.join(store.directory, 'repo_dir')
|
||||||
os.mkdir(repo_dir_path)
|
os.mkdir(repo_dir_path)
|
||||||
os.symlink(repo_dir_path, os.path.join(store.directory, 'fake_sha'))
|
os.symlink(
|
||||||
|
repo_dir_path,
|
||||||
|
os.path.join(store.directory, 'fake_sha' + '_' + hex_md5('url')),
|
||||||
|
)
|
||||||
|
|
||||||
ret = store.clone('url', 'fake_sha')
|
ret = store.clone('url', 'fake_sha')
|
||||||
assert ret == repo_dir_path
|
assert ret == repo_dir_path
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue