@@ -95,6 +95,25 @@ 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
+ [ TestCase ( @"dir\foo.txt" , "a.b." , @"dir\foo.txt" , "a.b.c.d." , 2 ) ]
102
+ [ TestCase ( @"dir\unrelated.txt" , "x.x.x.x." , @"dir\foo.txt" , "a.b.c.d." , 4 ) ]
103
+ public async Task Rename ( string oldPath , string oldContent , string newPath , string newContent , int expectLinesAdded )
104
+ {
105
+ using ( var temp = new TempRepository ( ) )
106
+ {
107
+ var commit1 = AddCommit ( temp . Repository , oldPath , oldContent . Replace ( '.' , '\n ' ) ) ;
108
+ var commit2 = AddCommit ( temp . Repository , newPath , newContent . Replace ( '.' , '\n ' ) ) ;
109
+ var contentBytes = new UTF8Encoding ( false ) . GetBytes ( newContent . Replace ( '.' , '\n ' ) ) ;
110
+ var target = new GitService ( new RepositoryFacade ( ) ) ;
111
+
112
+ var changes = await target . CompareWith ( temp . Repository , commit1 . Sha , commit2 . Sha , newPath , contentBytes ) ;
113
+
114
+ Assert . That ( changes ? . LinesAdded , Is . EqualTo ( expectLinesAdded ) ) ;
115
+ }
116
+ }
98
117
}
99
118
100
119
public class TheCreateLocalRepositoryModelMethod
@@ -406,14 +425,25 @@ static Commit AddCommit(Repository repo, string path = "file.txt", string conten
406
425
content = content ?? Guid . NewGuid ( ) . ToString ( ) ;
407
426
408
427
var dir = repo . Info . WorkingDirectory ;
428
+ DeleteFilesNotInGit ( dir ) ;
409
429
var file = Path . Combine ( dir , path ) ;
430
+ Directory . CreateDirectory ( Path . GetDirectoryName ( file ) ) ;
410
431
File . WriteAllText ( file , content ) ;
411
- Commands . Stage ( repo , path ) ;
432
+ Commands . Stage ( repo , "*" ) ;
412
433
var signature = new Signature ( "foobar" , "[email protected] " , DateTime . Now ) ;
413
434
var commit = repo . Commit ( "message" , signature , signature ) ;
414
435
return commit ;
415
436
}
416
437
438
+ static void DeleteFilesNotInGit ( string dir )
439
+ {
440
+ var gitDir = Path . Combine ( dir , @".git\" ) ;
441
+ Directory . GetFiles ( dir , "*" , SearchOption . AllDirectories )
442
+ . Where ( f => ! f . StartsWith ( gitDir , StringComparison . OrdinalIgnoreCase ) )
443
+ . ToList ( )
444
+ . ForEach ( File . Delete ) ;
445
+ }
446
+
417
447
protected class TempRepository : TempDirectory
418
448
{
419
449
public TempRepository ( )
0 commit comments