@@ -181,9 +181,11 @@ def test_img_conflict(img_staged, patch_dir):
181181
182182
183183@pytest .fixture
184- def submodule_with_commits (tempdir_factory ):
184+ def repo_with_commits (tempdir_factory ):
185185 path = git_dir (tempdir_factory )
186186 with cwd (path ):
187+ open ('foo' , 'a+' ).close ()
188+ cmd_output ('git' , 'add' , 'foo' )
187189 git_commit ()
188190 rev1 = cmd_output ('git' , 'rev-parse' , 'HEAD' )[1 ].strip ()
189191 git_commit ()
@@ -196,18 +198,21 @@ def checkout_submodule(rev):
196198
197199
198200@pytest .fixture
199- def sub_staged (submodule_with_commits , tempdir_factory ):
201+ def sub_staged (repo_with_commits , tempdir_factory ):
200202 path = git_dir (tempdir_factory )
201203 with cwd (path ):
204+ open ('bar' , 'a+' ).close ()
205+ cmd_output ('git' , 'add' , 'bar' )
206+ git_commit ()
202207 cmd_output (
203- 'git' , 'submodule' , 'add' , submodule_with_commits .path , 'sub' ,
208+ 'git' , 'submodule' , 'add' , repo_with_commits .path , 'sub' ,
204209 )
205- checkout_submodule (submodule_with_commits .rev1 )
210+ checkout_submodule (repo_with_commits .rev1 )
206211 cmd_output ('git' , 'add' , 'sub' )
207212 yield auto_namedtuple (
208213 path = path ,
209214 sub_path = os .path .join (path , 'sub' ),
210- submodule = submodule_with_commits ,
215+ submodule = repo_with_commits ,
211216 )
212217
213218
@@ -242,6 +247,34 @@ def test_sub_something_unstaged(sub_staged, patch_dir):
242247 _test_sub_state (sub_staged , 'rev2' , 'AM' )
243248
244249
250+ def test_submodule_does_not_discard_changes (sub_staged , patch_dir ):
251+ with open ('bar' , 'w' ) as f :
252+ f .write ('unstaged changes' )
253+
254+ foo_path = os .path .join (sub_staged .sub_path , 'foo' )
255+ with open (foo_path , 'w' ) as f :
256+ f .write ('foo contents' )
257+
258+ with staged_files_only (patch_dir ):
259+ with open ('bar' ) as f :
260+ assert f .read () == ''
261+
262+ with open (foo_path ) as f :
263+ assert f .read () == 'foo contents'
264+
265+ with open ('bar' ) as f :
266+ assert f .read () == 'unstaged changes'
267+
268+ with open (foo_path ) as f :
269+ assert f .read () == 'foo contents'
270+
271+
272+ def test_submodule_does_not_discard_changes_recurse (sub_staged , patch_dir ):
273+ cmd_output ('git' , 'config' , 'submodule.recurse' , '1' , cwd = sub_staged .path )
274+
275+ test_submodule_does_not_discard_changes (sub_staged , patch_dir )
276+
277+
245278def test_stage_utf8_changes (foo_staged , patch_dir ):
246279 contents = '\u2603 '
247280 with open ('foo' , 'w' , encoding = 'UTF-8' ) as foo_file :
0 commit comments