@@ -95,6 +95,23 @@ public async Task Indent_Heuristic_Is_Enabled(string content1, string content2,
9595 Assert . That ( changes . Patch . Replace ( '\n ' , '.' ) , Contains . Substring ( expectPatch ) ) ;
9696 }
9797 }
98+
99+ [ TestCase ( "foo.txt" , "a.b." , "bar.txt" , "a.b.c.d." , 2 ) ]
100+ [ TestCase ( @"dir\foo.txt" , "a.b." , @"dir\bar.txt" , "a.b.c.d." , 2 ) ]
101+ public async Task Rename ( string oldPath , string oldContent , string newPath , string newContent , int expectLinesAdded )
102+ {
103+ using ( var temp = new TempRepository ( ) )
104+ {
105+ var commit1 = AddCommit ( temp . Repository , oldPath , oldContent . Replace ( '.' , '\n ' ) ) ;
106+ var commit2 = AddCommit ( temp . Repository , newPath , newContent . Replace ( '.' , '\n ' ) ) ;
107+ var contentBytes = new UTF8Encoding ( false ) . GetBytes ( newContent . Replace ( '.' , '\n ' ) ) ;
108+ var target = new GitService ( new RepositoryFacade ( ) ) ;
109+
110+ var changes = await target . CompareWith ( temp . Repository , commit1 . Sha , commit2 . Sha , newPath , contentBytes ) ;
111+
112+ Assert . That ( changes ? . LinesAdded , Is . EqualTo ( expectLinesAdded ) ) ;
113+ }
114+ }
98115 }
99116
100117 public class TheCreateLocalRepositoryModelMethod
@@ -406,14 +423,25 @@ static Commit AddCommit(Repository repo, string path = "file.txt", string conten
406423 content = content ?? Guid . NewGuid ( ) . ToString ( ) ;
407424
408425 var dir = repo . Info . WorkingDirectory ;
426+ DeleteFilesNotInGit ( dir ) ;
409427 var file = Path . Combine ( dir , path ) ;
428+ Directory . CreateDirectory ( Path . GetDirectoryName ( file ) ) ;
410429 File . WriteAllText ( file , content ) ;
411- Commands . Stage ( repo , path ) ;
430+ Commands . Stage ( repo , "*" ) ;
412431 var signature = new Signature ( "foobar" , "foobar@github.com" , DateTime . Now ) ;
413432 var commit = repo . Commit ( "message" , signature , signature ) ;
414433 return commit ;
415434 }
416435
436+ static void DeleteFilesNotInGit ( string dir )
437+ {
438+ var gitDir = Path . Combine ( dir , @".git\" ) ;
439+ Directory . GetFiles ( dir , "*" , SearchOption . AllDirectories )
440+ . Where ( f => ! f . StartsWith ( gitDir , StringComparison . OrdinalIgnoreCase ) )
441+ . ToList ( )
442+ . ForEach ( File . Delete ) ;
443+ }
444+
417445 protected class TempRepository : TempDirectory
418446 {
419447 public TempRepository ( )
0 commit comments