4
4
using System . Text ;
5
5
using LibGit2Sharp . Tests . TestHelpers ;
6
6
using Xunit ;
7
- using Xunit . Extensions ;
8
7
9
8
namespace LibGit2Sharp . Tests
10
9
{
@@ -20,7 +19,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
20
19
{
21
20
Tree tree = repo . Head . Tip . Tree ;
22
21
23
- using ( var changes = repo . Diff . Compare < TreeChanges > ( tree , tree ) )
22
+ using ( var changes = repo . Diff . Compare < TreeChanges > ( tree , tree ) )
24
23
{
25
24
Assert . Empty ( changes ) ;
26
25
}
@@ -112,13 +111,13 @@ public void CanDetectABinaryChange()
112
111
113
112
File . AppendAllText ( filepath , "abcdef" ) ;
114
113
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 } ) )
116
115
Assert . True ( patch [ filename ] . IsBinaryComparison ) ;
117
116
118
117
Commands . Stage ( repo , filename ) ;
119
118
var commit2 = repo . Commit ( "Update binary file" , Constants . Signature , Constants . Signature ) ;
120
119
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 } ) )
122
121
Assert . True ( patch2 [ filename ] . IsBinaryComparison ) ;
123
122
}
124
123
}
@@ -138,13 +137,13 @@ public void CanDetectABinaryDeletion()
138
137
139
138
File . Delete ( filepath ) ;
140
139
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 } ) )
142
141
Assert . True ( patch [ filename ] . IsBinaryComparison ) ;
143
142
144
143
Commands . Remove ( repo , filename ) ;
145
144
var commit2 = repo . Commit ( "Delete binary file" , Constants . Signature , Constants . Signature ) ;
146
145
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 } ) )
148
147
Assert . True ( patch2 [ filename ] . IsBinaryComparison ) ;
149
148
}
150
149
}
@@ -704,7 +703,7 @@ public void CanIncludeUnmodifiedEntriesWhenEnabled()
704
703
Touch ( repo . Info . WorkingDirectory , "a.txt" , "abc\n def\n " ) ;
705
704
Touch ( repo . Info . WorkingDirectory , "b.txt" , "abc\n def\n " ) ;
706
705
707
- Commands . Stage ( repo , new [ ] { "a.txt" , "b.txt" } ) ;
706
+ Commands . Stage ( repo , new [ ] { "a.txt" , "b.txt" } ) ;
708
707
Commit old = repo . Commit ( "Initial" , Constants . Signature , Constants . Signature ) ;
709
708
710
709
File . AppendAllText ( Path . Combine ( repo . Info . WorkingDirectory , "b.txt" ) , "ghi\n jkl\n " ) ;
@@ -728,12 +727,12 @@ public void CanDetectTheExactRenamingExactCopyingOfNonModifiedAndModifiedFilesWh
728
727
var path = Repository . Init ( scd . DirectoryPath ) ;
729
728
using ( var repo = new Repository ( path ) )
730
729
{
731
- const string originalPath = "original.txt" ;
732
- const string renamedPath = "renamed.txt" ;
730
+ const string originalPath = "original.txt" ;
731
+ const string renamedPath = "renamed.txt" ;
733
732
const string originalPath2 = "original2.txt" ;
734
- const string copiedPath1 = "copied.txt" ;
733
+ const string copiedPath1 = "copied.txt" ;
735
734
const string originalPath3 = "original3.txt" ;
736
- const string copiedPath2 = "copied2.txt" ;
735
+ const string copiedPath2 = "copied2.txt" ;
737
736
738
737
Touch ( repo . Info . WorkingDirectory , originalPath , "a\n b\n c\n d\n " ) ;
739
738
Touch ( repo . Info . WorkingDirectory , originalPath2 , "1\n 2\n 3\n 4\n " ) ;
@@ -986,7 +985,7 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityNone()
986
985
Assert . Single ( changes . Deleted ) ;
987
986
Assert . Single ( changes . TypeChanged ) ;
988
987
989
- TreeEntryChanges change = changes . Single ( c => c . Path == path ) ;
988
+ TreeEntryChanges change = changes . Single ( c => c . Path == path ) ;
990
989
Assert . Equal ( Mode . SymbolicLink , change . OldMode ) ;
991
990
Assert . Equal ( Mode . NonExecutableFile , change . Mode ) ;
992
991
Assert . Equal ( ChangeKind . TypeChanged , change . Status ) ;
@@ -1087,7 +1086,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
1087
1086
using ( var repo = new Repository ( path ) )
1088
1087
{
1089
1088
SetFilemode ( repo , true ) ;
1090
- using ( var changes = repo . Diff . Compare < TreeChanges > ( new [ ] { file } ) )
1089
+ using ( var changes = repo . Diff . Compare < TreeChanges > ( new [ ] { file } ) )
1091
1090
{
1092
1091
Assert . Single ( changes ) ;
1093
1092
@@ -1147,6 +1146,44 @@ public void RetrievingDiffChangesMustAlwaysBeCaseSensitive()
1147
1146
}
1148
1147
}
1149
1148
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
+
1150
1187
[ Fact ]
1151
1188
public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff ( )
1152
1189
{
0 commit comments