mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-07 17:40:06 -06:00
added create repo
This commit is contained in:
2
Makefile
2
Makefile
@@ -30,7 +30,7 @@ coverage: py_env
|
||||
coverage run `which py.test` tests $(TEST_TARGETS) && \
|
||||
coverage report -m'
|
||||
|
||||
py_env: requirements.txt
|
||||
py_env: requirements.txt setup.py
|
||||
rm -rf py_env
|
||||
virtualenv py_env
|
||||
bash -c 'source py_env/bin/activate && \
|
||||
|
||||
@@ -11,6 +11,12 @@ def get_pre_commit_path():
|
||||
return os.path.join(get_root(), '.git/hooks/pre-commit')
|
||||
|
||||
|
||||
def get_env_path():
|
||||
return os.path.join(get_root(), '.pre-commit')
|
||||
|
||||
def create_pre_commit_package_dir():
|
||||
local.path(get_root() + '/.pre-commit').mkdir()
|
||||
|
||||
def create_pre_commit():
|
||||
path = get_pre_commit_path()
|
||||
pre_commit_file = pkg_resources.resource_filename('pre_commit', 'resources/pre-commit.sh')
|
||||
@@ -20,8 +26,11 @@ def create_pre_commit():
|
||||
def remove_pre_commit():
|
||||
local.path(get_pre_commit_path()).delete()
|
||||
|
||||
def create_repo_in_env(name, git_repo_path):
|
||||
create_pre_commit_package_dir()
|
||||
|
||||
env_path = get_env_path()
|
||||
|
||||
|
||||
|
||||
|
||||
with local.cwd(env_path):
|
||||
local['git']['clone', git_repo_path, name]()
|
||||
print local.cwd.getpath()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import pytest
|
||||
|
||||
@@ -7,30 +6,28 @@ from plumbum import local
|
||||
from pre_commit import git
|
||||
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_dir(dir):
|
||||
old_path = local.cwd.getpath()
|
||||
local.cwd.chdir(dir)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
local.cwd.chdir(old_path)
|
||||
|
||||
@pytest.yield_fixture
|
||||
def empty_git_dir(tmpdir):
|
||||
with in_dir(tmpdir.strpath):
|
||||
with local.cwd(tmpdir.strpath):
|
||||
local['git']['init']()
|
||||
yield tmpdir.strpath
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def dummy_git_repo(empty_git_dir):
|
||||
local['touch']['dummy']()
|
||||
local['git']['add', 'dummy']()
|
||||
local['git']['commit', '-m', 'dummy commit']()
|
||||
|
||||
yield empty_git_dir
|
||||
|
||||
def test_get_root(empty_git_dir):
|
||||
assert git.get_root() == empty_git_dir
|
||||
|
||||
foo = local.path('foo')
|
||||
foo.mkdir()
|
||||
|
||||
with in_dir(foo):
|
||||
with local.cwd(foo):
|
||||
assert git.get_root() == empty_git_dir
|
||||
|
||||
|
||||
@@ -52,3 +49,7 @@ def test_remove_pre_commit(empty_git_dir):
|
||||
git.remove_pre_commit()
|
||||
|
||||
assert not os.path.exists(git.get_pre_commit_path())
|
||||
|
||||
|
||||
def test_create_repo_in_env(empty_git_dir, dummy_git_repo):
|
||||
git.create_repo_in_env('pre-commit', dummy_git_repo)
|
||||
Reference in New Issue
Block a user