66
77import pre_commit .constants as C
88from pre_commit .clientlib .validate_config import load_config
9- from pre_commit .commands .autoupdate import _update_repository
9+ from pre_commit .commands .autoupdate import _update_repo
1010from pre_commit .commands .autoupdate import autoupdate
1111from pre_commit .commands .autoupdate import RepositoryCannotBeUpdatedError
1212from pre_commit .ordereddict import OrderedDict
@@ -32,7 +32,7 @@ def up_to_date_repo(tempdir_factory):
3232def test_up_to_date_repo (up_to_date_repo , runner_with_mocked_store ):
3333 config = make_config_from_repo (up_to_date_repo )
3434 input_sha = config ['sha' ]
35- ret = _update_repository (config , runner_with_mocked_store )
35+ ret = _update_repo (config , runner_with_mocked_store , tags_only = False )
3636 assert ret ['sha' ] == input_sha
3737
3838
@@ -45,8 +45,7 @@ def test_autoupdate_up_to_date_repo(
4545
4646 before = open (C .CONFIG_FILE ).read ()
4747 assert '^$' not in before
48- runner = Runner ('.' , C .CONFIG_FILE )
49- ret = autoupdate (runner )
48+ ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), tags_only = False )
5049 after = open (C .CONFIG_FILE ).read ()
5150 assert ret == 0
5251 assert before == after
@@ -71,7 +70,7 @@ def test_out_of_date_repo(out_of_date_repo, runner_with_mocked_store):
7170 config = make_config_from_repo (
7271 out_of_date_repo .path , sha = out_of_date_repo .original_sha ,
7372 )
74- ret = _update_repository (config , runner_with_mocked_store )
73+ ret = _update_repo (config , runner_with_mocked_store , tags_only = False )
7574 assert ret ['sha' ] != out_of_date_repo .original_sha
7675 assert ret ['sha' ] == out_of_date_repo .head_sha
7776
@@ -86,8 +85,7 @@ def test_autoupdate_out_of_date_repo(
8685 write_config ('.' , config )
8786
8887 before = open (C .CONFIG_FILE ).read ()
89- runner = Runner ('.' , C .CONFIG_FILE )
90- ret = autoupdate (runner )
88+ ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), tags_only = False )
9189 after = open (C .CONFIG_FILE ).read ()
9290 assert ret == 0
9391 assert before != after
@@ -111,7 +109,28 @@ def test_autoupdate_tagged_repo(
111109 )
112110 write_config ('.' , config )
113111
114- ret = autoupdate (Runner ('.' , C .CONFIG_FILE ))
112+ ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), tags_only = False )
113+ assert ret == 0
114+ assert 'v1.2.3' in open (C .CONFIG_FILE ).read ()
115+
116+
117+ @pytest .yield_fixture
118+ def tagged_repo_with_more_commits (tagged_repo ):
119+ with cwd (tagged_repo .path ):
120+ cmd_output ('git' , 'commit' , '--allow-empty' , '-m' , 'commit!' )
121+ yield tagged_repo
122+
123+
124+ def test_autoupdate_tags_only (
125+ tagged_repo_with_more_commits , in_tmpdir , mock_out_store_directory ,
126+ ):
127+ config = make_config_from_repo (
128+ tagged_repo_with_more_commits .path ,
129+ sha = tagged_repo_with_more_commits .original_sha ,
130+ )
131+ write_config ('.' , config )
132+
133+ ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), tags_only = True )
115134 assert ret == 0
116135 assert 'v1.2.3' in open (C .CONFIG_FILE ).read ()
117136
@@ -141,7 +160,7 @@ def test_hook_disppearing_repo_raises(
141160 hooks = [OrderedDict ((('id' , 'foo' ),))],
142161 )
143162 with pytest .raises (RepositoryCannotBeUpdatedError ):
144- _update_repository (config , runner_with_mocked_store )
163+ _update_repo (config , runner_with_mocked_store , tags_only = False )
145164
146165
147166def test_autoupdate_hook_disappearing_repo (
@@ -156,8 +175,7 @@ def test_autoupdate_hook_disappearing_repo(
156175 write_config ('.' , config )
157176
158177 before = open (C .CONFIG_FILE ).read ()
159- runner = Runner ('.' , C .CONFIG_FILE )
160- ret = autoupdate (runner )
178+ ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), tags_only = False )
161179 after = open (C .CONFIG_FILE ).read ()
162180 assert ret == 1
163181 assert before == after
@@ -168,7 +186,7 @@ def test_autoupdate_local_hooks(tempdir_factory):
168186 config = config_with_local_hooks ()
169187 path = add_config_to_repo (git_path , config )
170188 runner = Runner (path , C .CONFIG_FILE )
171- assert autoupdate (runner ) == 0
189+ assert autoupdate (runner , tags_only = False ) == 0
172190 new_config_writen = load_config (runner .config_file_path )
173191 assert len (new_config_writen ) == 1
174192 assert new_config_writen [0 ] == config
@@ -184,7 +202,7 @@ def test_autoupdate_local_hooks_with_out_of_date_repo(
184202 config = [local_config , stale_config ]
185203 write_config ('.' , config )
186204 runner = Runner ('.' , C .CONFIG_FILE )
187- assert autoupdate (runner ) == 0
205+ assert autoupdate (runner , tags_only = False ) == 0
188206 new_config_writen = load_config (runner .config_file_path )
189207 assert len (new_config_writen ) == 2
190208 assert new_config_writen [0 ] == local_config
0 commit comments