44using System . Text ;
55using LibGit2Sharp . Tests . TestHelpers ;
66using Xunit ;
7- using Xunit . Extensions ;
87
98namespace LibGit2Sharp . Tests
109{
@@ -20,7 +19,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
2019 {
2120 Tree tree = repo . Head . Tip . Tree ;
2221
23- using ( var changes = repo . Diff . Compare < TreeChanges > ( tree , tree ) )
22+ using ( var changes = repo . Diff . Compare < TreeChanges > ( tree , tree ) )
2423 {
2524 Assert . Empty ( changes ) ;
2625 }
@@ -112,13 +111,13 @@ public void CanDetectABinaryChange()
112111
113112 File . AppendAllText ( filepath , "abcdef" ) ;
114113
115- using ( var patch = repo . Diff . Compare < Patch > ( commit . Tree , DiffTargets . WorkingDirectory , new [ ] { filename } ) )
114+ using ( var patch = repo . Diff . Compare < Patch > ( commit . Tree , DiffTargets . WorkingDirectory , new [ ] { filename } ) )
116115 Assert . True ( patch [ filename ] . IsBinaryComparison ) ;
117116
118117 Commands . Stage ( repo , filename ) ;
119118 var commit2 = repo . Commit ( "Update binary file" , Constants . Signature , Constants . Signature ) ;
120119
121- using ( var patch2 = repo . Diff . Compare < Patch > ( commit . Tree , commit2 . Tree , new [ ] { filename } ) )
120+ using ( var patch2 = repo . Diff . Compare < Patch > ( commit . Tree , commit2 . Tree , new [ ] { filename } ) )
122121 Assert . True ( patch2 [ filename ] . IsBinaryComparison ) ;
123122 }
124123 }
@@ -138,13 +137,13 @@ public void CanDetectABinaryDeletion()
138137
139138 File . Delete ( filepath ) ;
140139
141- using ( var patch = repo . Diff . Compare < Patch > ( commit . Tree , DiffTargets . WorkingDirectory , new [ ] { filename } ) )
140+ using ( var patch = repo . Diff . Compare < Patch > ( commit . Tree , DiffTargets . WorkingDirectory , new [ ] { filename } ) )
142141 Assert . True ( patch [ filename ] . IsBinaryComparison ) ;
143142
144143 Commands . Remove ( repo , filename ) ;
145144 var commit2 = repo . Commit ( "Delete binary file" , Constants . Signature , Constants . Signature ) ;
146145
147- using ( var patch2 = repo . Diff . Compare < Patch > ( commit . Tree , commit2 . Tree , new [ ] { filename } ) )
146+ using ( var patch2 = repo . Diff . Compare < Patch > ( commit . Tree , commit2 . Tree , new [ ] { filename } ) )
148147 Assert . True ( patch2 [ filename ] . IsBinaryComparison ) ;
149148 }
150149 }
@@ -704,7 +703,7 @@ public void CanIncludeUnmodifiedEntriesWhenEnabled()
704703 Touch ( repo . Info . WorkingDirectory , "a.txt" , "abc\n def\n " ) ;
705704 Touch ( repo . Info . WorkingDirectory , "b.txt" , "abc\n def\n " ) ;
706705
707- Commands . Stage ( repo , new [ ] { "a.txt" , "b.txt" } ) ;
706+ Commands . Stage ( repo , new [ ] { "a.txt" , "b.txt" } ) ;
708707 Commit old = repo . Commit ( "Initial" , Constants . Signature , Constants . Signature ) ;
709708
710709 File . AppendAllText ( Path . Combine ( repo . Info . WorkingDirectory , "b.txt" ) , "ghi\n jkl\n " ) ;
@@ -728,12 +727,12 @@ public void CanDetectTheExactRenamingExactCopyingOfNonModifiedAndModifiedFilesWh
728727 var path = Repository . Init ( scd . DirectoryPath ) ;
729728 using ( var repo = new Repository ( path ) )
730729 {
731- const string originalPath = "original.txt" ;
732- const string renamedPath = "renamed.txt" ;
730+ const string originalPath = "original.txt" ;
731+ const string renamedPath = "renamed.txt" ;
733732 const string originalPath2 = "original2.txt" ;
734- const string copiedPath1 = "copied.txt" ;
733+ const string copiedPath1 = "copied.txt" ;
735734 const string originalPath3 = "original3.txt" ;
736- const string copiedPath2 = "copied2.txt" ;
735+ const string copiedPath2 = "copied2.txt" ;
737736
738737 Touch ( repo . Info . WorkingDirectory , originalPath , "a\n b\n c\n d\n " ) ;
739738 Touch ( repo . Info . WorkingDirectory , originalPath2 , "1\n 2\n 3\n 4\n " ) ;
@@ -986,7 +985,7 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityNone()
986985 Assert . Single ( changes . Deleted ) ;
987986 Assert . Single ( changes . TypeChanged ) ;
988987
989- TreeEntryChanges change = changes . Single ( c => c . Path == path ) ;
988+ TreeEntryChanges change = changes . Single ( c => c . Path == path ) ;
990989 Assert . Equal ( Mode . SymbolicLink , change . OldMode ) ;
991990 Assert . Equal ( Mode . NonExecutableFile , change . Mode ) ;
992991 Assert . Equal ( ChangeKind . TypeChanged , change . Status ) ;
@@ -1087,7 +1086,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
10871086 using ( var repo = new Repository ( path ) )
10881087 {
10891088 SetFilemode ( repo , true ) ;
1090- using ( var changes = repo . Diff . Compare < TreeChanges > ( new [ ] { file } ) )
1089+ using ( var changes = repo . Diff . Compare < TreeChanges > ( new [ ] { file } ) )
10911090 {
10921091 Assert . Single ( changes ) ;
10931092
@@ -1147,6 +1146,44 @@ public void RetrievingDiffChangesMustAlwaysBeCaseSensitive()
11471146 }
11481147 }
11491148
1149+ [ Fact ]
1150+ public void RetrievingDiffContainsRightAmountOfAddedAndDeletedLines ( )
1151+ {
1152+ ObjectId treeOldOid , treeNewOid ;
1153+
1154+ string repoPath = InitNewRepository ( ) ;
1155+
1156+ using ( var repo = new Repository ( repoPath ) )
1157+ {
1158+ Blob oldContent = OdbHelper . CreateBlob ( repo , "awesome content\n " ) ;
1159+ Blob newContent = OdbHelper . CreateBlob ( repo , "more awesome content\n " ) ;
1160+
1161+ var td = new TreeDefinition ( )
1162+ . Add ( "A.TXT" , oldContent , Mode . NonExecutableFile )
1163+ . Add ( "a.txt" , oldContent , Mode . NonExecutableFile ) ;
1164+
1165+ treeOldOid = repo . ObjectDatabase . CreateTree ( td ) . Id ;
1166+
1167+ td = new TreeDefinition ( )
1168+ . Add ( "A.TXT" , newContent , Mode . NonExecutableFile )
1169+ . Add ( "a.txt" , newContent , Mode . NonExecutableFile ) ;
1170+
1171+ treeNewOid = repo . ObjectDatabase . CreateTree ( td ) . Id ;
1172+ }
1173+
1174+ using ( var repo = new Repository ( repoPath ) )
1175+ {
1176+ using ( var changes = repo . Diff . Compare < Patch > ( repo . Lookup < Tree > ( treeOldOid ) , repo . Lookup < Tree > ( treeNewOid ) ) )
1177+ {
1178+ foreach ( var entry in changes )
1179+ {
1180+ Assert . Single ( entry . AddedLines ) ;
1181+ Assert . Single ( entry . DeletedLines ) ;
1182+ }
1183+ }
1184+ }
1185+ }
1186+
11501187 [ Fact ]
11511188 public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff ( )
11521189 {
0 commit comments