Repository: pre-commit/pre-commit

Issue:
multiple mutable rev warnings issued on `autoupdate`
when running `pre-commit autoupdate` I get 2 warnings per mutable rev, when I expected 0 see #974

```sh
~/projects/pytest-cov   pre-commit-autoupdate  pipx run pre-commit autoupdate    
[WARNING] The 'rev' field of repo 'https://github.com/pre-commit/pre-commit-hooks' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://github.com/timothycrosley/isort' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://gitlab.com/pycqa/flake8' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://github.com/pre-commit/pre-commit-hooks' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://github.com/timothycrosley/isort' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
[WARNING] The 'rev' field of repo 'https://gitlab.com/pycqa/flake8' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
Updating https://github.com/pre-commit/pre-commit-hooks ... updating master -> v4.0.1.
Updating https://github.com/timothycrosley/isort ... updating master -> 5.9.3.
Updating https://gitlab.com/pycqa/flake8 ... updating master -> 3.9.2.
```


Discussion:
this affects all config validation checks (e.g. also unknown keywords), as the config is validated twice ([migration](https://github.com/pre-commit/pre-commit/blob/559d8a78d11881c8db352f64bfc926b9d66e151d/pre_commit/commands/migrate_config.py#L44) and [updating](https://github.com/pre-commit/pre-commit/blob/559d8a78d11881c8db352f64bfc926b9d66e151d/pre_commit/commands/autoupdate.py#L146)).

This might be fixable by suppressing the `logger.warning` output if the migration is being called with `silent=True`, as it is done whilst autoupdating. If this sounds like a reasonable approach to you @asottile, I can change/add this if you want.

(this context should do the trick)
```python
import logging

from contextlib import contextmanager
from typing import Generator

@contextmanager
def suppress_warnings(logger: logging.Logger) -> Generator[None, None, None]:
    old_level = logger.getEffectiveLevel()
    logger.setLevel(logging.ERROR)

    try:
        yield
    finally:
        logger.setLevel(old_level)
```
since this is cosmetic and harmless I don't want to do any invasive "fixes" for this, but I suspect this line can be removed (as it will need to be removed anyway when list-based configurations are finally removed in 3.x): https://github.com/pre-commit/pre-commit/blob/509e4e20e86b5db48bc827753dcdfcdbbd706812/pre_commit/commands/migrate_config.py#L43-L44

Resolving patch:
diff --git a/pre_commit/commands/migrate_config.py b/pre_commit/commands/migrate_config.py
--- a/pre_commit/commands/migrate_config.py
+++ b/pre_commit/commands/migrate_config.py
@@ -3,7 +3,6 @@
 
 import yaml
 
-from pre_commit.clientlib import load_config
 from pre_commit.util import yaml_load
 
 
@@ -40,9 +39,6 @@ def _migrate_sha_to_rev(contents: str) -> str:
 
 
 def migrate_config(config_file: str, quiet: bool = False) -> int:
-    # ensure that the configuration is a valid pre-commit configuration
-    load_config(config_file)
-
     with open(config_file) as f:
         orig_contents = contents = f.read()
 


Test patch:
diff --git a/tests/commands/migrate_config_test.py b/tests/commands/migrate_config_test.py
--- a/tests/commands/migrate_config_test.py
+++ b/tests/commands/migrate_config_test.py
@@ -1,7 +1,4 @@
-import pytest
-
 import pre_commit.constants as C
-from pre_commit.clientlib import InvalidConfigError
 from pre_commit.commands.migrate_config import migrate_config
 
 
@@ -130,13 +127,3 @@ def test_migrate_config_sha_to_rev(tmpdir):
         '    rev: v1.2.0\n'
         '    hooks: []\n'
     )
-
-
-@pytest.mark.parametrize('contents', ('', '\n'))
-def test_migrate_config_invalid_configuration(tmpdir, contents):
-    cfg = tmpdir.join(C.CONFIG_FILE)
-    cfg.write(contents)
-    with tmpdir.as_cwd(), pytest.raises(InvalidConfigError):
-        migrate_config(C.CONFIG_FILE)
-    # even though the config is invalid, this should be a noop
-    assert cfg.read() == contents