2
2
import datetime
3
3
import os
4
4
import pathlib
5
+ import random
5
6
import shutil
6
7
import textwrap
7
8
from typing import Callable , TypedDict
@@ -141,6 +142,7 @@ def test_repo_update_handle_cases(
141
142
) -> None :
142
143
git_repo : GitSync = constructor (** lazy_constructor_options (** locals ()))
143
144
git_repo .obtain () # clone initial repo
145
+
144
146
mocka = mocker .spy (git_repo , "run" )
145
147
git_repo .update_repo ()
146
148
@@ -154,6 +156,69 @@ def test_repo_update_handle_cases(
154
156
assert mocker .call (["symbolic-ref" , "--short" , "HEAD" ]) not in mocka .mock_calls
155
157
156
158
159
+ @pytest .mark .parametrize (
160
+ "has_untracked_files,needs_stash,has_remote_changes" ,
161
+ [
162
+ [True , True , True ],
163
+ [True , True , False ],
164
+ [True , False , True ],
165
+ [True , False , False ],
166
+ [False , True , True ],
167
+ [False , True , False ],
168
+ [False , False , True ],
169
+ [False , False , False ],
170
+ ],
171
+ )
172
+ def test_repo_update_stash_cases (
173
+ tmp_path : pathlib .Path ,
174
+ create_git_remote_repo : CreateProjectCallbackFixtureProtocol ,
175
+ mocker : MockerFixture ,
176
+ has_untracked_files : bool ,
177
+ needs_stash : bool ,
178
+ has_remote_changes : bool ,
179
+ ) -> None :
180
+ git_remote_repo = create_git_remote_repo ()
181
+
182
+ git_repo : GitSync = GitSync (
183
+ url = f"file://{ git_remote_repo } " ,
184
+ dir = tmp_path / "myrepo" ,
185
+ vcs = "git" ,
186
+ )
187
+ git_repo .obtain () # clone initial repo
188
+
189
+ def make_file (filename : str ) -> pathlib .Path :
190
+ some_file = git_repo .dir .joinpath (filename )
191
+ with open (some_file , "w" ) as file :
192
+ file .write ("some content: " + str (random .random ()))
193
+
194
+ return some_file
195
+
196
+ # Make an initial commit so we can reset
197
+ some_file = make_file ("initial_file" )
198
+ git_repo .run (["add" , some_file ])
199
+ git_repo .run (["commit" , "-m" , "a commit" ])
200
+ git_repo .run (["push" ])
201
+
202
+ if has_remote_changes :
203
+ some_file = make_file ("some_file" )
204
+ git_repo .run (["add" , some_file ])
205
+ git_repo .run (["commit" , "-m" , "a commit" ])
206
+ git_repo .run (["push" ])
207
+ git_repo .run (["reset" , "--hard" , "HEAD^" ])
208
+
209
+ if has_untracked_files :
210
+ make_file ("some_file" )
211
+
212
+ if needs_stash :
213
+ some_file = make_file ("some_stashed_file" )
214
+ git_repo .run (["add" , some_file ])
215
+
216
+ mocka = mocker .spy (git_repo , "run" )
217
+ git_repo .update_repo ()
218
+
219
+ mocka .assert_any_call (["symbolic-ref" , "--short" , "HEAD" ])
220
+
221
+
157
222
@pytest .mark .parametrize (
158
223
# Postpone evaluation of options so fixture variables can interpolate
159
224
"constructor,lazy_constructor_options" ,
0 commit comments