diff --git a/lib/glob.js b/lib/glob.js index 7b11c76..d3f0a83 100644 --- a/lib/glob.js +++ b/lib/glob.js @@ -14,7 +14,14 @@ function glob( globs, options ) { var negatives = []; globs.forEach( function ( glob ) { - var mm = new Minimatch( self.join( '/', glob ), options ); + var negate = new Minimatch( glob, options ).negate; + glob = glob.replace(/^[!]+/g, ''); + glob = self.join( '/', glob ); + if (negate) { + glob = self.join( '!', glob ); + } + + var mm = new Minimatch( glob, options ); mm.base = mmBase( mm ); if ( mm.negate ) negatives.push( mm ); diff --git a/test/clean.js b/test/clean.js index 1ec33a9..8265494 100644 --- a/test/clean.js +++ b/test/clean.js @@ -11,8 +11,17 @@ describe( 'clean', function () { it( '(preparing: create files to clean up later)', function ( done ) { - VinylFs.src( 'test/fixtures/**' ) - .pipe( VinylFs.dest( 'test/fixtures/cleaning' ) ) + VinylFs.src( 'test/fixtures/index.html' ) + .pipe( VinylFs.dest( 'test/fixtures/cleanthis' ) ) + .on( 'error', done ) + .on( 'end', done ); + + } ); + + it( '(preparing: create files to ignore in cleanup)', function ( done ) { + + VinylFs.src( 'test/fixtures/index.html' ) + .pipe( VinylFs.dest( 'test/fixtures/dontcleanthis' ) ) .on( 'error', done ) .on( 'end', done ); @@ -31,22 +40,27 @@ describe( 'clean', function () { it( '(preparing: remove files to clean)', function ( done ) { - rmdir( 'test/fixtures/cleaning', done ); + rmdir( 'test/fixtures/cleanthis', done ); + + } ); + + it( '(preparing: remove files to ignore in cleanup)', function ( done ) { + + rmdir( 'test/fixtures/dontcleanthis', done ); } ); - it( 'should clean up extra remote files', function ( done ) { + it( 'should clean up extra remote files but repect ignore rules', function ( done ) { done = suite.done( done ); - suite.vftp.clean( 'test/clean/**', 'test/fixtures' ) + suite.vftp.clean( [ 'test/clean/**/*', '!test/clean/dontcleanthis/**/*' ], 'test/fixtures' ) .on( 'error', done ) .on( 'end', check ); function check() { - - assert.ok( suite.log.match( /DEL/ ) ); - assert.ok( suite.log.match( /RMDIR/ ) ); + assert.ok( suite.log.match( /RMDIR(.)*test\/clean\/cleanthis/ ) ); + assert.equal( suite.log.match( /RMDIR(.)*test\/clean\/dontcleanthis/ ), null ); done(); }