@@ -278,5 +278,67 @@ public void CanCopeWithExternalChangesToTheIndex()
278278 Assert . Equal ( 2 , repoRead . Index . Count ) ;
279279 }
280280 }
281+
282+ [ Fact ]
283+ public void CanResetFullyMergedIndexFromTree ( )
284+ {
285+ string path = CloneStandardTestRepo ( ) ;
286+
287+ const string testFile = "new_tracked_file.txt" ;
288+
289+ // It is sufficient to check just one of the stage area changes, such as the added file,
290+ // to verify that the index has indeed been read from the tree.
291+ using ( var repo = new Repository ( path ) )
292+ {
293+ const string headIndexTreeSha = "e5d221fc5da11a3169bf503d76497c81be3207b6" ;
294+
295+ Assert . True ( repo . Index . IsFullyMerged ) ;
296+ Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( testFile ) ) ;
297+
298+ var headIndexTree = repo . Lookup < Tree > ( headIndexTreeSha ) ;
299+ Assert . NotNull ( headIndexTree ) ;
300+ repo . Index . Reset ( headIndexTree ) ;
301+
302+ Assert . True ( repo . Index . IsFullyMerged ) ;
303+ Assert . Equal ( FileStatus . Untracked , repo . Index . RetrieveStatus ( testFile ) ) ;
304+ }
305+
306+ // Check that the index was persisted to disk.
307+ using ( var repo = new Repository ( path ) )
308+ {
309+ Assert . Equal ( FileStatus . Untracked , repo . Index . RetrieveStatus ( testFile ) ) ;
310+ }
311+ }
312+
313+ [ Fact ]
314+ public void CanResetIndexWithUnmergedEntriesFromTree ( )
315+ {
316+ string path = CloneMergedTestRepo ( ) ;
317+
318+ const string testFile = "one.txt" ;
319+
320+ // It is sufficient to check just one of the stage area changes, such as the modified file,
321+ // to verify that the index has indeed been read from the tree.
322+ using ( var repo = new Repository ( path ) )
323+ {
324+ const string headIndexTreeSha = "1cb365141a52dfbb24933515820eb3045fbca12b" ;
325+
326+ Assert . False ( repo . Index . IsFullyMerged ) ;
327+ Assert . Equal ( FileStatus . Staged , repo . Index . RetrieveStatus ( testFile ) ) ;
328+
329+ var headIndexTree = repo . Lookup < Tree > ( headIndexTreeSha ) ;
330+ Assert . NotNull ( headIndexTree ) ;
331+ repo . Index . Reset ( headIndexTree ) ;
332+
333+ Assert . True ( repo . Index . IsFullyMerged ) ;
334+ Assert . Equal ( FileStatus . Modified , repo . Index . RetrieveStatus ( testFile ) ) ;
335+ }
336+
337+ // Check that the index was persisted to disk.
338+ using ( var repo = new Repository ( path ) )
339+ {
340+ Assert . Equal ( FileStatus . Modified , repo . Index . RetrieveStatus ( testFile ) ) ;
341+ }
342+ }
281343 }
282344}
0 commit comments