|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import os.path |
| 5 | +import shlex |
4 | 6 | import sqlite3 |
5 | 7 | import stat |
6 | 8 | from unittest import mock |
7 | 9 |
|
8 | 10 | import pytest |
9 | 11 |
|
| 12 | +import pre_commit.constants as C |
10 | 13 | from pre_commit import git |
11 | 14 | from pre_commit.store import _get_default_directory |
12 | 15 | from pre_commit.store import _LOCAL_RESOURCES |
@@ -91,6 +94,72 @@ def test_clone(store, tempdir_factory, caplog): |
91 | 94 | assert store.select_all_repos() == [(path, rev, ret)] |
92 | 95 |
|
93 | 96 |
|
| 97 | +def test_warning_for_deprecated_stages_on_init(store, tempdir_factory, caplog): |
| 98 | + manifest = '''\ |
| 99 | +- id: hook1 |
| 100 | + name: hook1 |
| 101 | + language: system |
| 102 | + entry: echo hook1 |
| 103 | + stages: [commit, push] |
| 104 | +- id: hook2 |
| 105 | + name: hook2 |
| 106 | + language: system |
| 107 | + entry: echo hook2 |
| 108 | + stages: [push, merge-commit] |
| 109 | +''' |
| 110 | + |
| 111 | + path = git_dir(tempdir_factory) |
| 112 | + with open(os.path.join(path, C.MANIFEST_FILE), 'w') as f: |
| 113 | + f.write(manifest) |
| 114 | + cmd_output('git', 'add', '.', cwd=path) |
| 115 | + git_commit(cwd=path) |
| 116 | + rev = git.head_rev(path) |
| 117 | + |
| 118 | + store.clone(path, rev) |
| 119 | + assert caplog.record_tuples[1] == ( |
| 120 | + 'pre_commit', |
| 121 | + logging.WARNING, |
| 122 | + f'repo `{path}` uses deprecated stage names ' |
| 123 | + f'(commit, push, merge-commit) which will be removed in a future ' |
| 124 | + f'version. ' |
| 125 | + f'Hint: often `pre-commit autoupdate --repo {shlex.quote(path)}` ' |
| 126 | + f'will fix this. ' |
| 127 | + f'if it does not -- consider reporting an issue to that repo.', |
| 128 | + ) |
| 129 | + |
| 130 | + # should not re-warn |
| 131 | + caplog.clear() |
| 132 | + store.clone(path, rev) |
| 133 | + assert caplog.record_tuples == [] |
| 134 | + |
| 135 | + |
| 136 | +def test_no_warning_for_non_deprecated_stages_on_init( |
| 137 | + store, tempdir_factory, caplog, |
| 138 | +): |
| 139 | + manifest = '''\ |
| 140 | +- id: hook1 |
| 141 | + name: hook1 |
| 142 | + language: system |
| 143 | + entry: echo hook1 |
| 144 | + stages: [pre-commit, pre-push] |
| 145 | +- id: hook2 |
| 146 | + name: hook2 |
| 147 | + language: system |
| 148 | + entry: echo hook2 |
| 149 | + stages: [pre-push, pre-merge-commit] |
| 150 | +''' |
| 151 | + |
| 152 | + path = git_dir(tempdir_factory) |
| 153 | + with open(os.path.join(path, C.MANIFEST_FILE), 'w') as f: |
| 154 | + f.write(manifest) |
| 155 | + cmd_output('git', 'add', '.', cwd=path) |
| 156 | + git_commit(cwd=path) |
| 157 | + rev = git.head_rev(path) |
| 158 | + |
| 159 | + store.clone(path, rev) |
| 160 | + assert logging.WARNING not in {tup[1] for tup in caplog.record_tuples} |
| 161 | + |
| 162 | + |
94 | 163 | def test_clone_cleans_up_on_checkout_failure(store): |
95 | 164 | with pytest.raises(Exception) as excinfo: |
96 | 165 | # This raises an exception because you can't clone something that |
|
0 commit comments