File tree Expand file tree Collapse file tree 3 files changed +27
-17
lines changed
Expand file tree Collapse file tree 3 files changed +27
-17
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ coverage: py_env
3030 coverage run ` which py.test` tests $(TEST_TARGETS ) && \
3131 coverage report -m'
3232
33- py_env : requirements.txt
33+ py_env : requirements.txt setup.py
3434 rm -rf py_env
3535 virtualenv py_env
3636 bash -c ' source py_env/bin/activate && \
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ def get_pre_commit_path():
1111 return os .path .join (get_root (), '.git/hooks/pre-commit' )
1212
1313
14+ def get_env_path ():
15+ return os .path .join (get_root (), '.pre-commit' )
16+
17+ def create_pre_commit_package_dir ():
18+ local .path (get_root () + '/.pre-commit' ).mkdir ()
19+
1420def create_pre_commit ():
1521 path = get_pre_commit_path ()
1622 pre_commit_file = pkg_resources .resource_filename ('pre_commit' , 'resources/pre-commit.sh' )
@@ -20,8 +26,11 @@ def create_pre_commit():
2026def remove_pre_commit ():
2127 local .path (get_pre_commit_path ()).delete ()
2228
29+ def create_repo_in_env (name , git_repo_path ):
30+ create_pre_commit_package_dir ()
2331
32+ env_path = get_env_path ()
2433
25-
26-
27-
34+ with local . cwd ( env_path ):
35+ local [ 'git' ][ 'clone' , git_repo_path , name ]()
36+ print local . cwd . getpath ()
Original file line number Diff line number Diff line change 11
2- import contextlib
32import os
43import pytest
54
65from plumbum import local
76from pre_commit import git
87
98
10-
11- @contextlib .contextmanager
12- def in_dir (dir ):
13- old_path = local .cwd .getpath ()
14- local .cwd .chdir (dir )
15- try :
16- yield
17- finally :
18- local .cwd .chdir (old_path )
19-
209@pytest .yield_fixture
2110def empty_git_dir (tmpdir ):
22- with in_dir (tmpdir .strpath ):
11+ with local . cwd (tmpdir .strpath ):
2312 local ['git' ]['init' ]()
2413 yield tmpdir .strpath
2514
2615
16+ @pytest .yield_fixture
17+ def dummy_git_repo (empty_git_dir ):
18+ local ['touch' ]['dummy' ]()
19+ local ['git' ]['add' , 'dummy' ]()
20+ local ['git' ]['commit' , '-m' , 'dummy commit' ]()
21+
22+ yield empty_git_dir
23+
2724def test_get_root (empty_git_dir ):
2825 assert git .get_root () == empty_git_dir
2926
3027 foo = local .path ('foo' )
3128 foo .mkdir ()
3229
33- with in_dir (foo ):
30+ with local . cwd (foo ):
3431 assert git .get_root () == empty_git_dir
3532
3633
@@ -52,3 +49,7 @@ def test_remove_pre_commit(empty_git_dir):
5249 git .remove_pre_commit ()
5350
5451 assert not os .path .exists (git .get_pre_commit_path ())
52+
53+
54+ def test_create_repo_in_env (empty_git_dir , dummy_git_repo ):
55+ git .create_repo_in_env ('pre-commit' , dummy_git_repo )
You can’t perform that action at this time.
0 commit comments