@@ -69,9 +69,14 @@ public void InitCallbackNotMadeWhenFilterNeverUsed()
6969 initializeCallback ) ;
7070 var registration = GlobalSettings . RegisterFilter ( filter ) ;
7171
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+ }
7580 }
7681
7782 [ Fact ]
@@ -89,16 +94,22 @@ public void InitCallbackMadeWhenUsingTheFilter()
8994 successCallback ,
9095 initializeCallback ) ;
9196 var registration = GlobalSettings . RegisterFilter ( filter ) ;
92- Assert . False ( called ) ;
9397
94- string repoPath = InitNewRepository ( ) ;
95- using ( var repo = CreateTestRepository ( repoPath ) )
98+ try
9699 {
97- StageNewFile ( repo ) ;
98- Assert . True ( called ) ;
99- }
100+ Assert . False ( called ) ;
100101
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+ }
102113 }
103114
104115 [ Fact ]
@@ -116,13 +127,18 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
116127 var filter = new FakeFilter ( FilterName , attributes , clean ) ;
117128 var registration = GlobalSettings . RegisterFilter ( filter ) ;
118129
119- using ( var repo = CreateTestRepository ( repoPath ) )
130+ try
120131 {
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 ) ;
123141 }
124-
125- GlobalSettings . DeregisterFilter ( registration ) ;
126142 }
127143
128144 [ Fact ]
@@ -138,17 +154,22 @@ public void CleanFilterWritesOutputToObjectTree()
138154 var filter = new FakeFilter ( FilterName , attributes , cleanCallback ) ;
139155 var registration = GlobalSettings . RegisterFilter ( filter ) ;
140156
141- using ( var repo = CreateTestRepository ( repoPath ) )
157+ try
142158 {
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 ;
146164
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 ) ;
149172 }
150-
151- GlobalSettings . DeregisterFilter ( registration ) ;
152173 }
153174
154175 [ Fact ]
@@ -165,19 +186,24 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
165186 var filter = new FakeFilter ( FilterName , attributes , null , smudgeCallback ) ;
166187 var registration = GlobalSettings . RegisterFilter ( filter ) ;
167188
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 ) ;
173192
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+ }
175201 }
176202
177203 [ Fact ]
178204 public void CanFilterLargeFiles ( )
179205 {
180- const int ContentLength = 128 * 1024 * 1024 ;
206+ const int ContentLength = 128 * 1024 * 1024 - 13 ;
181207 const char ContentValue = 'x' ;
182208
183209 char [ ] content = ( new string ( ContentValue , 1024 ) ) . ToCharArray ( ) ;
@@ -187,51 +213,60 @@ public void CanFilterLargeFiles()
187213 var filter = new FileExportFilter ( FilterName , attributes ) ;
188214 var registration = GlobalSettings . RegisterFilter ( filter ) ;
189215
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
193217 {
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 } )
195221 {
196- writer . Write ( content ) ;
197- }
198- }
222+ int remain = ContentLength ;
199223
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+ }
202231
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 ) ;
205234
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 } ;
215237
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 ) )
224239 {
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 } ) ;
227246 }
228247
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+ }
231260
232- contentFile . Delete ( ) ;
261+ Assert . Equal ( ContentLength , totalRead ) ;
262+ }
233263
234- GlobalSettings . DeregisterFilter ( registration ) ;
264+ contentFile . Delete ( ) ;
265+ }
266+ finally
267+ {
268+ GlobalSettings . DeregisterFilter ( registration ) ;
269+ }
235270 }
236271
237272 [ Fact ]
0 commit comments