@@ -180,6 +180,70 @@ def test_ci_key_must_be_map():
180180 cfgv .validate ({'ci' : 'invalid' , 'repos' : []}, CONFIG_SCHEMA )
181181
182182
183+ @pytest .mark .parametrize (
184+ 'rev' ,
185+ (
186+ 'v0.12.4' ,
187+ 'b27f281' ,
188+ 'b27f281eb9398fc8504415d7fbdabf119ea8c5e1' ,
189+ '19.10b0' ,
190+ '4.3.21-2' ,
191+ ),
192+ )
193+ def test_warn_mutable_rev_ok (caplog , rev ):
194+ config_obj = {
195+ 'repo' : 'https://gitlab.com/pycqa/flake8' ,
196+ 'rev' : rev ,
197+ 'hooks' : [{'id' : 'flake8' }],
198+ }
199+ cfgv .validate (config_obj , CONFIG_REPO_DICT )
200+
201+ assert caplog .record_tuples == []
202+
203+
204+ @pytest .mark .parametrize (
205+ 'rev' ,
206+ (
207+ '' ,
208+ 'HEAD' ,
209+ 'stable' ,
210+ 'master' ,
211+ 'some_branch_name' ,
212+ ),
213+ )
214+ def test_warn_mutable_rev_invalid (caplog , rev ):
215+ config_obj = {
216+ 'repo' : 'https://gitlab.com/pycqa/flake8' ,
217+ 'rev' : rev ,
218+ 'hooks' : [{'id' : 'flake8' }],
219+ }
220+ cfgv .validate (config_obj , CONFIG_REPO_DICT )
221+
222+ assert caplog .record_tuples == [
223+ (
224+ 'pre_commit' ,
225+ logging .WARNING ,
226+ "The 'rev' field of repo 'https://gitlab.com/pycqa/flake8' "
227+ 'appears to be a mutable reference (moving tag / branch). '
228+ 'Mutable references are never updated after first install and are '
229+ 'not supported. '
230+ 'See https://pre-commit.com/#using-the-latest-version-for-a-repository ' # noqa: E501
231+ 'for more details.' ,
232+ ),
233+ ]
234+
235+
236+ def test_warn_mutable_rev_conditional ():
237+ config_obj = {
238+ 'repo' : 'meta' ,
239+ 'rev' : '3.7.7' ,
240+ 'hooks' : [{'id' : 'flake8' }],
241+ }
242+
243+ with pytest .raises (cfgv .ValidationError ):
244+ cfgv .validate (config_obj , CONFIG_REPO_DICT )
245+
246+
183247def test_validate_optional_sensible_regex (caplog ):
184248 config_obj = {
185249 'id' : 'flake8' ,
0 commit comments