Skip to content

Commit e3d1f10

Browse files
committed
added create repo
1 parent 94370d6 commit e3d1f10

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 && \

pre_commit/git.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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+
1420
def 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():
2026
def 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()

tests/git_test.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11

2-
import contextlib
32
import os
43
import pytest
54

65
from plumbum import local
76
from 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
2110
def 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+
2724
def 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)

0 commit comments

Comments
 (0)