Example #1
0
def check_pre_commit_hook(
    term: Terminal, pre_commit_hook: PreCommitHook
) -> None:
    if pre_commit_hook.exists():
        if pre_commit_hook.is_autohooks_pre_commit_hook():
            term.ok('autohooks pre-commit hook is active.')

            if pre_commit_hook.is_current_autohooks_pre_commit_hook():
                term.ok('autohooks pre-commit hook is up-to-date.')
            else:
                term.warning(
                    'autohooks pre-commit hook is outdated. Please run '
                    '\'autohooks activate --force\' to update your pre-commit '
                    'hook.'
                )

            hook_mode = pre_commit_hook.read_mode()
            if hook_mode == Mode.UNKNOWN:
                term.warning(
                    f'Unknown autohooks mode in {str(pre_commit_hook)}. '
                    f'Falling back to "{str(hook_mode.get_effective_mode())}" '
                    'mode.'
                )
        else:
            term.error(
                'autohooks pre-commit hook is not active. But a different '
                f'pre-commit hook has been found at {str(pre_commit_hook)}.'
            )

    else:
        term.error(
            'autohooks pre-commit hook not active. Please run \'autohooks '
            'activate\'.'
        )
Example #2
0
    def test_pre_commit_template(self):
        template = PreCommitTemplate()
        path = FakeReadPath(template.render(mode=Mode.PIPENV))
        pre_commit_hook = PreCommitHook(path)

        self.assertTrue(pre_commit_hook.is_autohooks_pre_commit_hook())
Example #3
0
    def test_other_hook(self):
        path = FakeReadPath('foo\nbar')
        pre_commit_hook = PreCommitHook(path)

        self.assertFalse(pre_commit_hook.is_autohooks_pre_commit_hook())