Ejemplo n.º 1
0
def check_hook_is_current(term: Terminal,
                          pre_commit_hook: PreCommitHook) -> None:
    if not pre_commit_hook.is_current_autohooks_pre_commit_hook():
        term.warning(
            'autohooks pre-commit hook is outdated. Please run '
            '\'autohooks activate --force\' to update your pre-commit '
            'hook.')
Ejemplo n.º 2
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\'.'
        )
Ejemplo n.º 3
0
    def test_modified_pre_commit_template(self):
        template = PreCommitTemplate()
        rendered = template.render(mode=Mode.PIPENV)
        lines = rendered.split('\n')
        lines[1] = ""
        path = FakeReadPath("\n".join(lines))
        pre_commit_hook = PreCommitHook(path)

        self.assertFalse(
            pre_commit_hook.is_current_autohooks_pre_commit_hook())
Ejemplo n.º 4
0
    def test_other_hook(self):
        path = FakeReadPath('foo\nbar')
        pre_commit_hook = PreCommitHook(path)

        self.assertFalse(
            pre_commit_hook.is_current_autohooks_pre_commit_hook())
Ejemplo n.º 5
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_current_autohooks_pre_commit_hook())