11from __future__ import absolute_import
2+ from __future__ import unicode_literals
23
34import mock
45import os
1617from pre_commit .prefixed_command_runner import PrefixedCommandRunner
1718from pre_commit .runner import Runner
1819from pre_commit .store import Store
20+ from testing .fixtures import git_dir
1921from testing .util import copy_tree_to_path
2022from testing .util import get_head_sha
2123from testing .util import get_resource_path
2224
2325
26+ git = local ['git' ]
27+
28+
2429@pytest .yield_fixture
2530def tmpdir_factory (tmpdir ):
2631 class TmpdirFactory (object ):
@@ -43,23 +48,19 @@ def in_tmpdir(tmpdir_factory):
4348 yield path
4449
4550
46- @pytest .yield_fixture
47- def empty_git_dir (in_tmpdir ):
48- local ['git' ]('init' )
49- yield in_tmpdir
50-
51-
5251def add_and_commit ():
53- local [ ' git' ] ('add' , '.' )
54- local [ ' git' ] ('commit' , '-m' , 'random commit {0}' .format (time .time ()))
52+ git ('add' , '.' )
53+ git ('commit' , '-m' , 'random commit {0}' .format (time .time ()))
5554
5655
5756@pytest .yield_fixture
58- def dummy_git_repo (empty_git_dir ):
59- # This is needed otherwise there is no `HEAD`
60- local ['touch' ]('dummy' )
61- add_and_commit ()
62- yield empty_git_dir
57+ def dummy_git_repo (tmpdir_factory ):
58+ path = git_dir (tmpdir_factory )
59+ with local .cwd (path ):
60+ # This is needed otherwise there is no `HEAD`
61+ local ['touch' ]('dummy' )
62+ add_and_commit ()
63+ yield path
6364
6465
6566def _make_repo (repo_path , repo_source ):
@@ -192,40 +193,48 @@ def _make_repo_from_configs(*configs):
192193
193194
194195@pytest .yield_fixture
195- def repo_with_passing_hook (config_for_script_hooks_repo , empty_git_dir ):
196- _make_repo_from_configs (config_for_script_hooks_repo )
197- yield empty_git_dir
196+ def repo_with_passing_hook (config_for_script_hooks_repo , tmpdir_factory ):
197+ path = git_dir (tmpdir_factory )
198+ with local .cwd (path ):
199+ _make_repo_from_configs (config_for_script_hooks_repo )
200+ yield path
198201
199202
200203@pytest .yield_fixture
201- def repo_with_failing_hook (failing_hook_repo , empty_git_dir ):
202- _make_repo_from_configs (_make_config (failing_hook_repo , 'failing_hook' ))
203- yield empty_git_dir
204+ def repo_with_failing_hook (failing_hook_repo , tmpdir_factory ):
205+ path = git_dir (tmpdir_factory )
206+ with local .cwd (path ):
207+ _make_repo_from_configs (
208+ _make_config (failing_hook_repo , 'failing_hook' )
209+ )
210+ yield path
204211
205212
206213@pytest .yield_fixture
207214def in_merge_conflict (repo_with_passing_hook ):
208- local ['git' ]('add' , C .CONFIG_FILE )
209- local ['git' ]('commit' , '-m' 'add hooks file' )
210- local ['git' ]('clone' , '.' , 'foo' )
215+ local ['touch' ]('dummy' )
216+ git ('add' , 'dummy' )
217+ git ('add' , C .CONFIG_FILE )
218+ git ('commit' , '-m' 'add hooks file' )
219+ git ('clone' , '.' , 'foo' )
211220 with local .cwd ('foo' ):
212- local [ ' git' ] ('checkout' , 'origin/master' , '-b' , 'foo' )
221+ git ('checkout' , 'origin/master' , '-b' , 'foo' )
213222 with open ('conflict_file' , 'w' ) as conflict_file :
214223 conflict_file .write ('herp\n derp\n ' )
215- local [ ' git' ] ('add' , 'conflict_file' )
224+ git ('add' , 'conflict_file' )
216225 with open ('foo_only_file' , 'w' ) as foo_only_file :
217226 foo_only_file .write ('foo' )
218- local [ ' git' ] ('add' , 'foo_only_file' )
219- local [ ' git' ] ('commit' , '-m' , 'conflict_file' )
220- local [ ' git' ] ('checkout' , 'origin/master' , '-b' , 'bar' )
227+ git ('add' , 'foo_only_file' )
228+ git ('commit' , '-m' , 'conflict_file' )
229+ git ('checkout' , 'origin/master' , '-b' , 'bar' )
221230 with open ('conflict_file' , 'w' ) as conflict_file :
222231 conflict_file .write ('harp\n ddrp\n ' )
223- local [ ' git' ] ('add' , 'conflict_file' )
232+ git ('add' , 'conflict_file' )
224233 with open ('bar_only_file' , 'w' ) as bar_only_file :
225234 bar_only_file .write ('bar' )
226- local [ ' git' ] ('add' , 'bar_only_file' )
227- local [ ' git' ] ('commit' , '-m' , 'conflict_file' )
228- local [ ' git' ] ('merge' , 'foo' , retcode = None )
235+ git ('add' , 'bar_only_file' )
236+ git ('commit' , '-m' , 'conflict_file' )
237+ git ('merge' , 'foo' , retcode = None )
229238 yield os .path .join (repo_with_passing_hook , 'foo' )
230239
231240
0 commit comments