1010
1111import mock
1212
13+ import pre_commit .constants as C
1314from pre_commit .commands .install_uninstall import IDENTIFYING_HASH
1415from pre_commit .commands .install_uninstall import install
1516from pre_commit .commands .install_uninstall import is_our_pre_commit
@@ -53,7 +54,7 @@ def test_is_previous_pre_commit(in_tmpdir):
5354
5455def test_install_pre_commit (tempdir_factory ):
5556 path = git_dir (tempdir_factory )
56- runner = Runner (path )
57+ runner = Runner (path , C . CONFIG_FILE )
5758 ret = install (runner )
5859 assert ret == 0
5960 assert os .path .exists (runner .pre_commit_path )
@@ -87,7 +88,7 @@ def test_install_hooks_directory_not_present(tempdir_factory):
8788 hooks = os .path .join (path , '.git' , 'hooks' )
8889 if os .path .exists (hooks ): # pragma: no cover (latest git)
8990 shutil .rmtree (hooks )
90- runner = Runner (path )
91+ runner = Runner (path , C . CONFIG_FILE )
9192 install (runner )
9293 assert os .path .exists (runner .pre_commit_path )
9394
@@ -97,7 +98,7 @@ def test_install_hooks_dead_symlink(
9798 tempdir_factory ,
9899): # pragma: no cover (non-windows)
99100 path = git_dir (tempdir_factory )
100- runner = Runner (path )
101+ runner = Runner (path , C . CONFIG_FILE )
101102 mkdirp (os .path .dirname (runner .pre_commit_path ))
102103 os .symlink ('/fake/baz' , os .path .join (path , '.git' , 'hooks' , 'pre-commit' ))
103104 install (runner )
@@ -106,14 +107,14 @@ def test_install_hooks_dead_symlink(
106107
107108def test_uninstall_does_not_blow_up_when_not_there (tempdir_factory ):
108109 path = git_dir (tempdir_factory )
109- runner = Runner (path )
110+ runner = Runner (path , C . CONFIG_FILE )
110111 ret = uninstall (runner )
111112 assert ret == 0
112113
113114
114115def test_uninstall (tempdir_factory ):
115116 path = git_dir (tempdir_factory )
116- runner = Runner (path )
117+ runner = Runner (path , C . CONFIG_FILE )
117118 assert not os .path .exists (runner .pre_commit_path )
118119 install (runner )
119120 assert os .path .exists (runner .pre_commit_path )
@@ -156,7 +157,7 @@ def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
156157def test_install_pre_commit_and_run (tempdir_factory ):
157158 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
158159 with cwd (path ):
159- assert install (Runner (path )) == 0
160+ assert install (Runner (path , C . CONFIG_FILE )) == 0
160161
161162 ret , output = _get_commit_output (tempdir_factory )
162163 assert ret == 0
@@ -172,7 +173,7 @@ def test_install_in_submodule_and_run(tempdir_factory):
172173
173174 sub_pth = os .path .join (parent_path , 'sub' )
174175 with cwd (sub_pth ):
175- assert install (Runner (sub_pth )) == 0
176+ assert install (Runner (sub_pth , C . CONFIG_FILE )) == 0
176177 ret , output = _get_commit_output (tempdir_factory )
177178 assert ret == 0
178179 assert NORMAL_PRE_COMMIT_RUN .match (output )
@@ -189,7 +190,7 @@ def test_commit_am(tempdir_factory):
189190 with io .open ('unstaged' , 'w' ) as foo_file :
190191 foo_file .write ('Oh hai' )
191192
192- assert install (Runner (path )) == 0
193+ assert install (Runner (path , C . CONFIG_FILE )) == 0
193194
194195 ret , output = _get_commit_output (tempdir_factory )
195196 assert ret == 0
@@ -198,8 +199,8 @@ def test_commit_am(tempdir_factory):
198199def test_install_idempotent (tempdir_factory ):
199200 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
200201 with cwd (path ):
201- assert install (Runner (path )) == 0
202- assert install (Runner (path )) == 0
202+ assert install (Runner (path , C . CONFIG_FILE )) == 0
203+ assert install (Runner (path , C . CONFIG_FILE )) == 0
203204
204205 ret , output = _get_commit_output (tempdir_factory )
205206 assert ret == 0
@@ -219,7 +220,7 @@ def test_environment_not_sourced(tempdir_factory):
219220 with cwd (path ):
220221 # Patch the executable to simulate rming virtualenv
221222 with mock .patch .object (sys , 'executable' , '/bin/false' ):
222- assert install (Runner (path )) == 0
223+ assert install (Runner (path , C . CONFIG_FILE )) == 0
223224
224225 # Use a specific homedir to ignore --user installs
225226 homedir = tempdir_factory .get ()
@@ -257,7 +258,7 @@ def test_environment_not_sourced(tempdir_factory):
257258def test_failing_hooks_returns_nonzero (tempdir_factory ):
258259 path = make_consuming_repo (tempdir_factory , 'failing_hook_repo' )
259260 with cwd (path ):
260- assert install (Runner (path )) == 0
261+ assert install (Runner (path , C . CONFIG_FILE )) == 0
261262
262263 ret , output = _get_commit_output (tempdir_factory )
263264 assert ret == 1
@@ -275,7 +276,7 @@ def test_failing_hooks_returns_nonzero(tempdir_factory):
275276def test_install_existing_hooks_no_overwrite (tempdir_factory ):
276277 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
277278 with cwd (path ):
278- runner = Runner (path )
279+ runner = Runner (path , C . CONFIG_FILE )
279280
280281 # Write out an "old" hook
281282 mkdirp (os .path .dirname (runner .pre_commit_path ))
@@ -301,7 +302,7 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory):
301302def test_install_existing_hook_no_overwrite_idempotent (tempdir_factory ):
302303 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
303304 with cwd (path ):
304- runner = Runner (path )
305+ runner = Runner (path , C . CONFIG_FILE )
305306
306307 # Write out an "old" hook
307308 mkdirp (os .path .dirname (runner .pre_commit_path ))
@@ -330,7 +331,7 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory):
330331def test_failing_existing_hook_returns_1 (tempdir_factory ):
331332 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
332333 with cwd (path ):
333- runner = Runner (path )
334+ runner = Runner (path , C . CONFIG_FILE )
334335
335336 # Write out a failing "old" hook
336337 mkdirp (os .path .dirname (runner .pre_commit_path ))
@@ -349,7 +350,7 @@ def test_failing_existing_hook_returns_1(tempdir_factory):
349350def test_install_overwrite_no_existing_hooks (tempdir_factory ):
350351 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
351352 with cwd (path ):
352- assert install (Runner (path ), overwrite = True ) == 0
353+ assert install (Runner (path , C . CONFIG_FILE ), overwrite = True ) == 0
353354
354355 ret , output = _get_commit_output (tempdir_factory )
355356 assert ret == 0
@@ -359,7 +360,7 @@ def test_install_overwrite_no_existing_hooks(tempdir_factory):
359360def test_install_overwrite (tempdir_factory ):
360361 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
361362 with cwd (path ):
362- runner = Runner (path )
363+ runner = Runner (path , C . CONFIG_FILE )
363364
364365 # Write out the "old" hook
365366 mkdirp (os .path .dirname (runner .pre_commit_path ))
@@ -377,7 +378,7 @@ def test_install_overwrite(tempdir_factory):
377378def test_uninstall_restores_legacy_hooks (tempdir_factory ):
378379 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
379380 with cwd (path ):
380- runner = Runner (path )
381+ runner = Runner (path , C . CONFIG_FILE )
381382
382383 # Write out an "old" hook
383384 mkdirp (os .path .dirname (runner .pre_commit_path ))
@@ -398,7 +399,7 @@ def test_uninstall_restores_legacy_hooks(tempdir_factory):
398399def test_replace_old_commit_script (tempdir_factory ):
399400 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
400401 with cwd (path ):
401- runner = Runner (path )
402+ runner = Runner (path , C . CONFIG_FILE )
402403
403404 # Install a script that looks like our old script
404405 pre_commit_contents = io .open (
@@ -424,7 +425,7 @@ def test_replace_old_commit_script(tempdir_factory):
424425def test_uninstall_doesnt_remove_not_our_hooks (tempdir_factory ):
425426 path = git_dir (tempdir_factory )
426427 with cwd (path ):
427- runner = Runner (path )
428+ runner = Runner (path , C . CONFIG_FILE )
428429 mkdirp (os .path .dirname (runner .pre_commit_path ))
429430 with io .open (runner .pre_commit_path , 'w' ) as pre_commit_file :
430431 pre_commit_file .write ('#!/usr/bin/env bash\n echo 1\n ' )
@@ -449,7 +450,7 @@ def test_installs_hooks_with_hooks_True(
449450):
450451 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
451452 with cwd (path ):
452- install (Runner (path ), hooks = True )
453+ install (Runner (path , C . CONFIG_FILE ), hooks = True )
453454 ret , output = _get_commit_output (
454455 tempdir_factory , pre_commit_home = mock_out_store_directory ,
455456 )
@@ -461,7 +462,7 @@ def test_installs_hooks_with_hooks_True(
461462def test_installed_from_venv (tempdir_factory ):
462463 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
463464 with cwd (path ):
464- install (Runner (path ))
465+ install (Runner (path , C . CONFIG_FILE ))
465466 # No environment so pre-commit is not on the path when running!
466467 # Should still pick up the python from when we installed
467468 ret , output = _get_commit_output (
@@ -495,7 +496,7 @@ def test_pre_push_integration_failing(tempdir_factory):
495496 path = tempdir_factory .get ()
496497 cmd_output ('git' , 'clone' , upstream , path )
497498 with cwd (path ):
498- install (Runner (path ), hook_type = 'pre-push' )
499+ install (Runner (path , C . CONFIG_FILE ), hook_type = 'pre-push' )
499500 # commit succeeds because pre-commit is only installed for pre-push
500501 assert _get_commit_output (tempdir_factory )[0 ] == 0
501502
@@ -511,7 +512,7 @@ def test_pre_push_integration_accepted(tempdir_factory):
511512 path = tempdir_factory .get ()
512513 cmd_output ('git' , 'clone' , upstream , path )
513514 with cwd (path ):
514- install (Runner (path ), hook_type = 'pre-push' )
515+ install (Runner (path , C . CONFIG_FILE ), hook_type = 'pre-push' )
515516 assert _get_commit_output (tempdir_factory )[0 ] == 0
516517
517518 retc , output = _get_push_output (tempdir_factory )
@@ -525,7 +526,7 @@ def test_pre_push_integration_empty_push(tempdir_factory):
525526 path = tempdir_factory .get ()
526527 cmd_output ('git' , 'clone' , upstream , path )
527528 with cwd (path ):
528- install (Runner (path ), hook_type = 'pre-push' )
529+ install (Runner (path , C . CONFIG_FILE ), hook_type = 'pre-push' )
529530 _get_push_output (tempdir_factory )
530531 retc , output = _get_push_output (tempdir_factory )
531532 assert output == 'Everything up-to-date\n '
0 commit comments