@@ -156,7 +156,28 @@ def test_install_existing_hooks_no_overwrite(tmpdir_factory):
156156 assert EXISTING_COMMIT_RUN .match (output )
157157
158158 # Now install pre-commit (no-overwrite)
159- assert install (Runner (path )) == 0
159+ assert install (runner ) == 0
160+
161+ # We should run both the legacy and pre-commit hooks
162+ ret , output = _get_commit_output (tmpdir_factory )
163+ assert ret == 0
164+ assert output .startswith ('legacy hook\n ' )
165+ assert NORMAL_PRE_COMMIT_RUN .match (output [len ('legacy hook\n ' ):])
166+
167+
168+ def test_install_existing_hook_no_overwrite_idempotent (tmpdir_factory ):
169+ path = make_consuming_repo (tmpdir_factory , 'script_hooks_repo' )
170+ with local .cwd (path ):
171+ runner = Runner (path )
172+
173+ # Write out an "old" hook
174+ with io .open (runner .pre_commit_path , 'w' ) as hook_file :
175+ hook_file .write ('#!/usr/bin/env bash\n echo "legacy hook"\n ' )
176+ make_executable (runner .pre_commit_path )
177+
178+ # Install twice
179+ assert install (runner ) == 0
180+ assert install (runner ) == 0
160181
161182 # We should run both the legacy and pre-commit hooks
162183 ret , output = _get_commit_output (tmpdir_factory )
@@ -184,9 +205,36 @@ def test_failing_existing_hook_returns_1(tmpdir_factory):
184205 hook_file .write ('#!/usr/bin/env bash\n echo "fail!"\n exit 1\n ' )
185206 make_executable (runner .pre_commit_path )
186207
187- assert install (Runner ( path ) ) == 0
208+ assert install (runner ) == 0
188209
189210 # We should get a failure from the legacy hook
190211 ret , output = _get_commit_output (tmpdir_factory )
191212 assert ret == 1
192213 assert FAIL_OLD_HOOK .match (output )
214+
215+
216+ def test_install_overwrite_no_existing_hooks (tmpdir_factory ):
217+ path = make_consuming_repo (tmpdir_factory , 'script_hooks_repo' )
218+ with local .cwd (path ):
219+ assert install (Runner (path ), overwrite = True ) == 0
220+
221+ ret , output = _get_commit_output (tmpdir_factory )
222+ assert ret == 0
223+ assert NORMAL_PRE_COMMIT_RUN .match (output )
224+
225+
226+ def test_install_overwrite (tmpdir_factory ):
227+ path = make_consuming_repo (tmpdir_factory , 'script_hooks_repo' )
228+ with local .cwd (path ):
229+ runner = Runner (path )
230+
231+ # Write out the "old" hook
232+ with io .open (runner .pre_commit_path , 'w' ) as hook_file :
233+ hook_file .write ('#!/usr/bin/env bash\n echo "legacy hook"\n ' )
234+ make_executable (runner .pre_commit_path )
235+
236+ assert install (runner , overwrite = True ) == 0
237+
238+ ret , output = _get_commit_output (tmpdir_factory )
239+ assert ret == 0
240+ assert NORMAL_PRE_COMMIT_RUN .match (output )
0 commit comments