2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
- using LibGit2Sharp . Core ;
6
5
using LibGit2Sharp . Tests . TestHelpers ;
7
6
using Xunit ;
8
7
@@ -13,7 +12,7 @@ public class FilterFixture : BaseFixture
13
12
private const int GitPassThrough = - 30 ;
14
13
15
14
readonly Func < FilterSource , IEnumerable < string > , int > checkPassThrough = ( source , attr ) => GitPassThrough ;
16
- readonly Func < GitBufReader , GitBufWriter , int > successCallback = ( reader , writer ) => 0 ;
15
+ readonly Func < Stream , Stream , int > successCallback = ( reader , writer ) => 0 ;
17
16
readonly Func < FilterSource , IEnumerable < string > , int > checkSuccess = ( source , attr ) => 0 ;
18
17
19
18
private const string FilterName = "the-filter" ;
@@ -106,7 +105,7 @@ public void ApplyCallbackMadeWhenCheckCallbackReturnsZero()
106
105
{
107
106
bool called = false ;
108
107
109
- Func < GitBufReader , GitBufWriter , int > applyCallback = ( reader , writer ) =>
108
+ Func < Stream , Stream , int > applyCallback = ( reader , writer ) =>
110
109
{
111
110
called = true ;
112
111
return 0 ; //successCallback
@@ -131,7 +130,7 @@ public void ApplyCallbackNotMadeWhenCheckCallbackReturnsPassThrough()
131
130
{
132
131
bool called = false ;
133
132
134
- Func < GitBufReader , GitBufWriter , int > applyCallback = ( reader , writer ) =>
133
+ Func < Stream , Stream , int > applyCallback = ( reader , writer ) =>
135
134
{
136
135
called = true ;
137
136
return 0 ;
@@ -271,7 +270,7 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
271
270
string repoPath = InitNewRepository ( ) ;
272
271
bool called = false ;
273
272
274
- Func < GitBufReader , GitBufWriter , int > clean = ( reader , writer ) =>
273
+ Func < Stream , Stream , int > clean = ( reader , writer ) =>
275
274
{
276
275
called = true ;
277
276
return GitPassThrough ;
@@ -297,7 +296,7 @@ public void CleanFilterWritesOutputToObjectTree()
297
296
298
297
string repoPath = InitNewRepository ( ) ;
299
298
300
- Func < GitBufReader , GitBufWriter , int > cleanCallback = SubstitutionCipherFilter . RotateByThirteenPlaces ;
299
+ Func < Stream , Stream , int > cleanCallback = SubstitutionCipherFilter . RotateByThirteenPlaces ;
301
300
302
301
var filter = new FakeFilter ( FilterName + 16 , attributes , checkSuccess , cleanCallback ) ;
303
302
@@ -327,7 +326,7 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
327
326
const string branchName = "branch" ;
328
327
string repoPath = InitNewRepository ( ) ;
329
328
330
- Func < GitBufReader , GitBufWriter , int > smudgeCallback = SubstitutionCipherFilter . RotateByThirteenPlaces ;
329
+ Func < Stream , Stream , int > smudgeCallback = SubstitutionCipherFilter . RotateByThirteenPlaces ;
331
330
332
331
var filter = new FakeFilter ( FilterName + 17 , attributes , checkSuccess , null , smudgeCallback ) ;
333
332
GlobalSettings . RegisterFilter ( filter ) ;
@@ -341,6 +340,54 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
341
340
GlobalSettings . DeregisterFilter ( filter . Name ) ;
342
341
}
343
342
343
+ [ Fact ]
344
+ public void FilterStreamsAreCoherent ( )
345
+ {
346
+ string repoPath = InitNewRepository ( ) ;
347
+
348
+ bool ? inputCanWrite = null , inputCanRead = null , inputCanSeek = null ;
349
+ bool ? outputCanWrite = null , outputCanRead = null , outputCanSeek = null ;
350
+
351
+ Func < Stream , Stream , int > assertor = ( input , output ) =>
352
+ {
353
+ inputCanRead = input . CanRead ;
354
+ inputCanWrite = input . CanWrite ;
355
+ inputCanSeek = input . CanSeek ;
356
+
357
+ outputCanRead = output . CanRead ;
358
+ outputCanWrite = output . CanWrite ;
359
+ outputCanSeek = output . CanSeek ;
360
+
361
+ return GitPassThrough ;
362
+ } ;
363
+
364
+ var filter = new FakeFilter ( FilterName + 18 , attributes , checkSuccess , assertor , assertor ) ;
365
+
366
+ GlobalSettings . RegisterFilter ( filter ) ;
367
+
368
+ using ( var repo = CreateTestRepository ( repoPath ) )
369
+ {
370
+ StageNewFile ( repo ) ;
371
+ }
372
+
373
+ GlobalSettings . DeregisterFilter ( filter . Name ) ;
374
+
375
+ Assert . True ( inputCanRead . HasValue ) ;
376
+ Assert . True ( inputCanWrite . HasValue ) ;
377
+ Assert . True ( inputCanSeek . HasValue ) ;
378
+ Assert . True ( outputCanRead . HasValue ) ;
379
+ Assert . True ( outputCanWrite . HasValue ) ;
380
+ Assert . True ( outputCanSeek . HasValue ) ;
381
+
382
+ Assert . True ( inputCanRead . Value ) ;
383
+ Assert . False ( inputCanWrite . Value ) ;
384
+ Assert . False ( inputCanSeek . Value ) ;
385
+
386
+ Assert . False ( outputCanRead . Value ) ;
387
+ Assert . True ( outputCanWrite . Value ) ;
388
+ Assert . False ( outputCanSeek . Value ) ;
389
+ }
390
+
344
391
private FileInfo CheckoutFileForSmudge ( string repoPath , string branchName , string content )
345
392
{
346
393
FileInfo expectedPath ;
@@ -394,14 +441,14 @@ public EmptyFilter(string name, IEnumerable<string> attributes)
394
441
class FakeFilter : Filter
395
442
{
396
443
private readonly Func < FilterSource , IEnumerable < string > , int > checkCallBack ;
397
- private readonly Func < GitBufReader , GitBufWriter , int > cleanCallback ;
398
- private readonly Func < GitBufReader , GitBufWriter , int > smudgeCallback ;
444
+ private readonly Func < Stream , Stream , int > cleanCallback ;
445
+ private readonly Func < Stream , Stream , int > smudgeCallback ;
399
446
private readonly Func < int > initCallback ;
400
447
401
448
public FakeFilter ( string name , IEnumerable < string > attributes ,
402
449
Func < FilterSource , IEnumerable < string > , int > checkCallBack = null ,
403
- Func < GitBufReader , GitBufWriter , int > cleanCallback = null ,
404
- Func < GitBufReader , GitBufWriter , int > smudgeCallback = null ,
450
+ Func < Stream , Stream , int > cleanCallback = null ,
451
+ Func < Stream , Stream , int > smudgeCallback = null ,
405
452
Func < int > initCallback = null )
406
453
: base ( name , attributes )
407
454
{
@@ -416,12 +463,12 @@ protected override int Check(IEnumerable<string> attributes, FilterSource filter
416
463
return checkCallBack != null ? checkCallBack ( filterSource , attributes ) : base . Check ( attributes , filterSource ) ;
417
464
}
418
465
419
- protected override int Clean ( string path , GitBufReader input , GitBufWriter output )
466
+ protected override int Clean ( string path , Stream input , Stream output )
420
467
{
421
468
return cleanCallback != null ? cleanCallback ( input , output ) : base . Clean ( path , input , output ) ;
422
469
}
423
470
424
- protected override int Smudge ( string path , GitBufReader input , GitBufWriter output )
471
+ protected override int Smudge ( string path , Stream input , Stream output )
425
472
{
426
473
return smudgeCallback != null ? smudgeCallback ( input , output ) : base . Smudge ( path , input , output ) ;
427
474
}
0 commit comments