@@ -69,9 +69,14 @@ public void InitCallbackNotMadeWhenFilterNeverUsed()
69
69
initializeCallback ) ;
70
70
var registration = GlobalSettings . RegisterFilter ( filter ) ;
71
71
72
- Assert . False ( called ) ;
73
-
74
- GlobalSettings . DeregisterFilter ( registration ) ;
72
+ try
73
+ {
74
+ Assert . False ( called ) ;
75
+ }
76
+ finally
77
+ {
78
+ GlobalSettings . DeregisterFilter ( registration ) ;
79
+ }
75
80
}
76
81
77
82
[ Fact ]
@@ -89,16 +94,22 @@ public void InitCallbackMadeWhenUsingTheFilter()
89
94
successCallback ,
90
95
initializeCallback ) ;
91
96
var registration = GlobalSettings . RegisterFilter ( filter ) ;
92
- Assert . False ( called ) ;
93
97
94
- string repoPath = InitNewRepository ( ) ;
95
- using ( var repo = CreateTestRepository ( repoPath ) )
98
+ try
96
99
{
97
- StageNewFile ( repo );
98
- Assert . True ( called ) ;
99
- }
100
+ Assert . False ( called ) ;
100
101
101
- GlobalSettings . DeregisterFilter ( registration ) ;
102
+ string repoPath = InitNewRepository ( ) ;
103
+ using ( var repo = CreateTestRepository ( repoPath ) )
104
+ {
105
+ StageNewFile ( repo ) ;
106
+ Assert . True ( called ) ;
107
+ }
108
+ }
109
+ finally
110
+ {
111
+ GlobalSettings . DeregisterFilter ( registration ) ;
112
+ }
102
113
}
103
114
104
115
[ Fact ]
@@ -116,13 +127,18 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
116
127
var filter = new FakeFilter ( FilterName , attributes , clean ) ;
117
128
var registration = GlobalSettings . RegisterFilter ( filter ) ;
118
129
119
- using ( var repo = CreateTestRepository ( repoPath ) )
130
+ try
120
131
{
121
- StageNewFile ( repo ) ;
122
- Assert . True ( called ) ;
132
+ using ( var repo = CreateTestRepository ( repoPath ) )
133
+ {
134
+ StageNewFile ( repo ) ;
135
+ Assert . True ( called ) ;
136
+ }
137
+ }
138
+ finally
139
+ {
140
+ GlobalSettings . DeregisterFilter ( registration ) ;
123
141
}
124
-
125
- GlobalSettings . DeregisterFilter ( registration ) ;
126
142
}
127
143
128
144
[ Fact ]
@@ -138,17 +154,22 @@ public void CleanFilterWritesOutputToObjectTree()
138
154
var filter = new FakeFilter ( FilterName , attributes , cleanCallback ) ;
139
155
var registration = GlobalSettings . RegisterFilter ( filter ) ;
140
156
141
- using ( var repo = CreateTestRepository ( repoPath ) )
157
+ try
142
158
{
143
- FileInfo expectedFile = StageNewFile ( repo , decodedInput ) ;
144
- var commit = repo . Commit ( "Clean that file" ) ;
145
- var blob = ( Blob ) commit . Tree [ expectedFile . Name ] . Target ;
159
+ using ( var repo = CreateTestRepository ( repoPath ) )
160
+ {
161
+ FileInfo expectedFile = StageNewFile ( repo , decodedInput ) ;
162
+ var commit = repo . Commit ( "Clean that file" ) ;
163
+ var blob = ( Blob ) commit . Tree [ expectedFile . Name ] . Target ;
146
164
147
- var textDetected = blob . GetContentText ( ) ;
148
- Assert . Equal ( encodedInput , textDetected ) ;
165
+ var textDetected = blob . GetContentText ( ) ;
166
+ Assert . Equal ( encodedInput , textDetected ) ;
167
+ }
168
+ }
169
+ finally
170
+ {
171
+ GlobalSettings . DeregisterFilter ( registration ) ;
149
172
}
150
-
151
- GlobalSettings . DeregisterFilter ( registration ) ;
152
173
}
153
174
154
175
[ Fact ]
@@ -165,19 +186,24 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
165
186
var filter = new FakeFilter ( FilterName , attributes , null , smudgeCallback ) ;
166
187
var registration = GlobalSettings . RegisterFilter ( filter ) ;
167
188
168
- FileInfo expectedFile = CheckoutFileForSmudge ( repoPath , branchName , encodedInput ) ;
169
-
170
- string combine = Path . Combine ( repoPath , ".." , expectedFile . Name ) ;
171
- string readAllText = File . ReadAllText ( combine ) ;
172
- Assert . Equal ( decodedInput , readAllText ) ;
189
+ try
190
+ {
191
+ FileInfo expectedFile = CheckoutFileForSmudge ( repoPath , branchName , encodedInput ) ;
173
192
174
- GlobalSettings . DeregisterFilter ( registration ) ;
193
+ string combine = Path . Combine ( repoPath , ".." , expectedFile . Name ) ;
194
+ string readAllText = File . ReadAllText ( combine ) ;
195
+ Assert . Equal ( decodedInput , readAllText ) ;
196
+ }
197
+ finally
198
+ {
199
+ GlobalSettings . DeregisterFilter ( registration ) ;
200
+ }
175
201
}
176
202
177
203
[ Fact ]
178
204
public void CanFilterLargeFiles ( )
179
205
{
180
- const int ContentLength = 128 * 1024 * 1024 ;
206
+ const int ContentLength = 128 * 1024 * 1024 - 13 ;
181
207
const char ContentValue = 'x' ;
182
208
183
209
char [ ] content = ( new string ( ContentValue , 1024 ) ) . ToCharArray ( ) ;
@@ -187,51 +213,60 @@ public void CanFilterLargeFiles()
187
213
var filter = new FileExportFilter ( FilterName , attributes ) ;
188
214
var registration = GlobalSettings . RegisterFilter ( filter ) ;
189
215
190
- string filePath = Path . Combine ( Directory . GetParent ( repoPath ) . Parent . FullName , Guid . NewGuid ( ) . ToString ( ) + ".blob" ) ;
191
- FileInfo contentFile = new FileInfo ( filePath ) ;
192
- using ( var writer = new StreamWriter ( contentFile . OpenWrite ( ) ) { AutoFlush = true } )
216
+ try
193
217
{
194
- for ( int i = 0 ; i < ContentLength / content . Length ; i ++ )
218
+ string filePath = Path . Combine ( Directory . GetParent ( repoPath ) . Parent . FullName , Guid . NewGuid ( ) . ToString ( ) + ".blob" ) ;
219
+ FileInfo contentFile = new FileInfo ( filePath ) ;
220
+ using ( var writer = new StreamWriter ( contentFile . OpenWrite ( ) ) { AutoFlush = true } )
195
221
{
196
- writer . Write ( content ) ;
197
- }
198
- }
222
+ int remain = ContentLength ;
199
223
200
- string attributesPath = Path . Combine ( Directory . GetParent ( repoPath ) . Parent . FullName , ".gitattributes" ) ;
201
- FileInfo attributesFile = new FileInfo ( attributesPath ) ;
224
+ while ( remain > 0 )
225
+ {
226
+ int chunkSize = remain > content . Length ? content . Length : remain ;
227
+ writer . Write ( content , 0 , chunkSize ) ;
228
+ remain -= chunkSize ;
229
+ }
230
+ }
202
231
203
- string configPath = CreateConfigurationWithDummyUser ( Constants . Signature ) ;
204
- var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath } ;
232
+ string attributesPath = Path . Combine ( Directory . GetParent ( repoPath ) . Parent . FullName , ".gitattributes" ) ;
233
+ FileInfo attributesFile = new FileInfo ( attributesPath ) ;
205
234
206
- using ( Repository repo = new Repository ( repoPath , repositoryOptions ) )
207
- {
208
- File . WriteAllText ( attributesPath , "*.blob filter=test" ) ;
209
- repo . Stage ( attributesFile . Name ) ;
210
- repo . Stage ( contentFile . Name ) ;
211
- repo . Commit ( "test" ) ;
212
- contentFile . Delete ( ) ;
213
- repo . Checkout ( "HEAD" , new CheckoutOptions ( ) { CheckoutModifiers = CheckoutModifiers . Force } ) ;
214
- }
235
+ string configPath = CreateConfigurationWithDummyUser ( Constants . Signature ) ;
236
+ var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath } ;
215
237
216
- contentFile = new FileInfo ( filePath ) ;
217
- Assert . True ( contentFile . Exists , "Contents not restored correctly by forced checkout." ) ;
218
- using ( StreamReader reader = contentFile . OpenText ( ) )
219
- {
220
- int totalRead = 0 ;
221
- char [ ] block = new char [ 1024 ] ;
222
- int read ;
223
- while ( ( read = reader . Read ( block , 0 , block . Length ) ) > 0 )
238
+ using ( Repository repo = new Repository ( repoPath , repositoryOptions ) )
224
239
{
225
- Assert . True ( CharArrayAreEqual ( block , content , read ) ) ;
226
- totalRead += read ;
240
+ File . WriteAllText ( attributesPath , "*.blob filter=test" ) ;
241
+ repo . Stage ( attributesFile . Name ) ;
242
+ repo . Stage ( contentFile . Name ) ;
243
+ repo . Commit ( "test" ) ;
244
+ contentFile . Delete ( ) ;
245
+ repo . Checkout ( "HEAD" , new CheckoutOptions ( ) { CheckoutModifiers = CheckoutModifiers . Force } ) ;
227
246
}
228
247
229
- Assert . Equal ( ContentLength , totalRead ) ;
230
- }
248
+ contentFile = new FileInfo ( filePath ) ;
249
+ Assert . True ( contentFile . Exists , "Contents not restored correctly by forced checkout." ) ;
250
+ using ( StreamReader reader = contentFile . OpenText ( ) )
251
+ {
252
+ int totalRead = 0 ;
253
+ char [ ] block = new char [ 1024 ] ;
254
+ int read ;
255
+ while ( ( read = reader . Read ( block , 0 , block . Length ) ) > 0 )
256
+ {
257
+ Assert . True ( CharArrayAreEqual ( block , content , read ) ) ;
258
+ totalRead += read ;
259
+ }
231
260
232
- contentFile . Delete ( ) ;
261
+ Assert . Equal ( ContentLength , totalRead ) ;
262
+ }
233
263
234
- GlobalSettings . DeregisterFilter ( registration ) ;
264
+ contentFile . Delete ( ) ;
265
+ }
266
+ finally
267
+ {
268
+ GlobalSettings . DeregisterFilter ( registration ) ;
269
+ }
235
270
}
236
271
237
272
[ Fact ]
0 commit comments