@@ -95,6 +95,23 @@ public async Task Indent_Heuristic_Is_Enabled(string content1, string content2,
95
95
Assert . That ( changes . Patch . Replace ( '\n ' , '.' ) , Contains . Substring ( expectPatch ) ) ;
96
96
}
97
97
}
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
+ }
98
115
}
99
116
100
117
public class TheCreateLocalRepositoryModelMethod
@@ -406,14 +423,25 @@ static Commit AddCommit(Repository repo, string path = "file.txt", string conten
406
423
content = content ?? Guid . NewGuid ( ) . ToString ( ) ;
407
424
408
425
var dir = repo . Info . WorkingDirectory ;
426
+ DeleteFilesNotInGit ( dir ) ;
409
427
var file = Path . Combine ( dir , path ) ;
428
+ Directory . CreateDirectory ( Path . GetDirectoryName ( file ) ) ;
410
429
File . WriteAllText ( file , content ) ;
411
- Commands . Stage ( repo , path ) ;
430
+ Commands . Stage ( repo , "*" ) ;
412
431
var signature = new Signature ( "foobar" , "[email protected] " , DateTime . Now ) ;
413
432
var commit = repo . Commit ( "message" , signature , signature ) ;
414
433
return commit ;
415
434
}
416
435
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
+
417
445
protected class TempRepository : TempDirectory
418
446
{
419
447
public TempRepository ( )
0 commit comments