|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | import pre_commit.constants as C |
| 8 | +from pre_commit.clientlib.validate_config import load_config |
8 | 9 | from pre_commit.commands.autoupdate import _update_repository |
9 | 10 | from pre_commit.commands.autoupdate import autoupdate |
10 | 11 | from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError |
@@ -146,4 +147,24 @@ def test_autoupdate_local_hooks(tmpdir_factory): |
146 | 147 | git_path = git_dir(tmpdir_factory) |
147 | 148 | config = config_with_local_hooks() |
148 | 149 | path = add_config_to_repo(git_path, config) |
149 | | - assert autoupdate(Runner(path)) == 0 |
| 150 | + runner = Runner(path) |
| 151 | + assert autoupdate(runner) == 0 |
| 152 | + new_config_writen = load_config(runner.config_file_path) |
| 153 | + assert len(new_config_writen) == 1 |
| 154 | + assert new_config_writen[0] == config |
| 155 | + |
| 156 | + |
| 157 | +def test_autoupdate_local_hooks_with_out_of_date_repo( |
| 158 | + out_of_date_repo, in_tmpdir, mock_out_store_directory |
| 159 | +): |
| 160 | + stale_config = make_config_from_repo( |
| 161 | + out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False, |
| 162 | + ) |
| 163 | + local_config = config_with_local_hooks() |
| 164 | + config = [local_config, stale_config] |
| 165 | + write_config('.', config) |
| 166 | + runner = Runner('.') |
| 167 | + assert autoupdate(runner) == 0 |
| 168 | + new_config_writen = load_config(runner.config_file_path) |
| 169 | + assert len(new_config_writen) == 2 |
| 170 | + assert new_config_writen[0] == local_config |
0 commit comments