diff --git a/Makefile b/Makefile index 161f6d0f..9aedace0 100644 --- a/Makefile +++ b/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 && \ diff --git a/pre_commit/git.py b/pre_commit/git.py index 7f206125..e5bb2132 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -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() diff --git a/tests/git_test.py b/tests/git_test.py index c566b1f3..11c0454a 100644 --- a/tests/git_test.py +++ b/tests/git_test.py @@ -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) \ No newline at end of file