@@ -392,5 +392,37 @@ public void CanRemoveAnEntryFromTheIndex(string pathInTheIndex, FileStatus expec
392392 Assert . Equal ( expectedAfterStatus , after ) ;
393393 }
394394 }
395+
396+ [ Theory ]
397+ [ InlineData ( "new_untracked_file.txt" , FileStatus . Untracked , FileStatus . Added ) ]
398+ [ InlineData ( "modified_unstaged_file.txt" , FileStatus . Modified , FileStatus . Staged ) ]
399+ public void CanAddAnEntryToTheIndexFromAFileInTheWorkdir ( string pathInTheWorkdir , FileStatus expectedBeforeStatus , FileStatus expectedAfterStatus )
400+ {
401+ var path = SandboxStandardTestRepoGitDir ( ) ;
402+ using ( var repo = new Repository ( path ) )
403+ {
404+ var before = repo . RetrieveStatus ( pathInTheWorkdir ) ;
405+ Assert . Equal ( expectedBeforeStatus , before ) ;
406+
407+ repo . Index . Add ( pathInTheWorkdir ) ;
408+
409+ var after = repo . RetrieveStatus ( pathInTheWorkdir ) ;
410+ Assert . Equal ( expectedAfterStatus , after ) ;
411+ }
412+ }
413+
414+ [ Fact ]
415+ public void AddingAnEntryToTheIndexFromAUnknwonFileInTheWorkdirThrows ( )
416+ {
417+ var path = SandboxStandardTestRepoGitDir ( ) ;
418+ using ( var repo = new Repository ( path ) )
419+ {
420+ const string filePath = "i_dont_exist.txt" ;
421+ var before = repo . RetrieveStatus ( filePath ) ;
422+ Assert . Equal ( FileStatus . Nonexistent , before ) ;
423+
424+ Assert . Throws < NotFoundException > ( ( ) => repo . Index . Add ( filePath ) ) ;
425+ }
426+ }
395427 }
396428}
0 commit comments