Move get_head_sha into testing since it is only used by tests.

This commit is contained in:
Anthony Sottile 2014-04-14 09:57:38 -07:00
parent db6e1afc75
commit 94d626691f
5 changed files with 15 additions and 15 deletions

View file

@ -22,11 +22,6 @@ def get_root():
return _get_root_new()
def get_head_sha(git_repo_path):
with local.cwd(git_repo_path):
return local['git']['rev-parse', 'HEAD']().strip()
@memoize_by_cwd
def get_staged_files():
return local['git']['diff', '--staged', '--name-only']().splitlines()

View file

@ -2,6 +2,7 @@ import jsonschema
import os
import os.path
import shutil
from plumbum import local
TESTING_DIR = os.path.abspath(os.path.dirname(__file__))
@ -29,6 +30,11 @@ def copy_tree_to_path(src_dir, dest_dir):
shutil.copy(srcname, destname)
def get_head_sha(dir):
with local.cwd(dir):
return local['git']['rev-parse', 'HEAD']().strip()
def is_valid_according_to_schema(obj, schema):
try:
jsonschema.validate(obj, schema)

View file

@ -9,15 +9,14 @@ from asottile.ordereddict import OrderedDict
from asottile.yaml import ordered_dump
from plumbum import local
import pre_commit.constants as C
from pre_commit import commands
from pre_commit import git
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
from pre_commit.clientlib.validate_config import validate_config_extra
from pre_commit.jsonschema_extensions import apply_defaults
from pre_commit.runner import Runner
from testing.auto_namedtuple import auto_namedtuple
from testing.util import get_head_sha
from testing.util import get_resource_path
@ -53,7 +52,7 @@ def test_uninstall(empty_git_dir):
def up_to_date_repo(python_hooks_repo):
config = OrderedDict((
('repo', python_hooks_repo),
('sha', git.get_head_sha(python_hooks_repo)),
('sha', get_head_sha(python_hooks_repo)),
('hooks', [OrderedDict((('id', 'foo'), ('files', '')))]),
))
wrapped_config = apply_defaults([config], CONFIG_JSON_SCHEMA)
@ -90,14 +89,14 @@ def test_autoupdate_up_to_date_repo(up_to_date_repo):
def out_of_date_repo(python_hooks_repo):
config = OrderedDict((
('repo', python_hooks_repo),
('sha', git.get_head_sha(python_hooks_repo)),
('sha', get_head_sha(python_hooks_repo)),
('hooks', [OrderedDict((('id', 'foo'), ('files', '')))]),
))
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
validate_config_extra(config_wrapped)
config = config_wrapped[0]
local['git']['commit', '--allow-empty', '-m', 'foo']()
head_sha = git.get_head_sha(python_hooks_repo)
head_sha = get_head_sha(python_hooks_repo)
with open(os.path.join(python_hooks_repo, C.CONFIG_FILE), 'w') as file_obj:
file_obj.write(
@ -136,7 +135,7 @@ def test_autoupdate_out_of_date_repo(out_of_date_repo):
def hook_disappearing_repo(python_hooks_repo):
config = OrderedDict((
('repo', python_hooks_repo),
('sha', git.get_head_sha(python_hooks_repo)),
('sha', get_head_sha(python_hooks_repo)),
('hooks', [OrderedDict((('id', 'foo'), ('files', '')))]),
))
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)

View file

@ -6,11 +6,11 @@ import yaml
from plumbum import local
import pre_commit.constants as C
from pre_commit import git
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
from pre_commit.clientlib.validate_config import validate_config_extra
from pre_commit.jsonschema_extensions import apply_defaults
from testing.util import copy_tree_to_path
from testing.util import get_head_sha
from testing.util import get_resource_path
@ -78,7 +78,7 @@ def failing_hook_repo(dummy_git_repo):
def _make_config(path, hook_id, file_regex):
config = {
'repo': path,
'sha': git.get_head_sha(path),
'sha': get_head_sha(path),
'hooks': [{'id': hook_id, 'files': file_regex}],
}
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)

View file

@ -3,13 +3,13 @@ import os
import pytest
import pre_commit.constants as C
from pre_commit import git
from pre_commit import repository
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
from pre_commit.clientlib.validate_config import validate_config_extra
from pre_commit.jsonschema_extensions import apply_defaults
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
from pre_commit.repository import Repository
from testing.util import get_head_sha
@pytest.fixture
@ -17,7 +17,7 @@ def dummy_repo_config(dummy_git_repo):
# This is not a valid config, but it is pretty close
return {
'repo': dummy_git_repo,
'sha': git.get_head_sha(dummy_git_repo),
'sha': get_head_sha(dummy_git_repo),
'hooks': [],
}