Skip to content

Commit

Permalink
Fix for composer#2739 (and composer#1755), added support for director…
Browse files Browse the repository at this point in the history
…y excludes in the .gitignore file like /directory or directory/
  • Loading branch information
Sandy Pleyte committed Feb 27, 2014
1 parent e8a3fc5 commit 21109ad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Composer/Package/Archiver/BaseExcludeFilter.php
Expand Up @@ -140,8 +140,8 @@ protected function generatePattern($rule)
$pattern .= '/';
}

// remove delimiters as well as caret (^) from the regex
$pattern .= substr(Finder\Glob::toRegex($rule), 2, -1);
// remove delimiters as well as caret (^) and dollar sign ($) from the regex
$pattern .= substr(Finder\Glob::toRegex($rule), 2, -2) . '/*.*$';

return array($pattern . '#', $negate, false);
}
Expand Down
35 changes: 35 additions & 0 deletions tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php
Expand Up @@ -46,6 +46,24 @@ protected function setUp()
'B/sub/prefixD.foo',
'B/sub/prefixE.foo',
'B/sub/prefixF.foo',
'C/prefixA.foo',
'C/prefixB.foo',
'C/prefixC.foo',
'C/prefixD.foo',
'C/prefixE.foo',
'C/prefixF.foo',
'D/prefixA',
'D/prefixB',
'D/prefixC',
'D/prefixD',
'D/prefixE',
'D/prefixF',
'E/prefixA.foo',
'E/prefixB.foo',
'E/prefixC.foo',
'E/prefixD.foo',
'E/prefixE.foo',
'E/prefixF.foo',
'toplevelA.foo',
'toplevelB.foo',
'prefixA.foo',
Expand Down Expand Up @@ -91,6 +109,20 @@ public function testManualExcludes()
'/B/sub/prefixD.foo',
'/B/sub/prefixE.foo',
'/B/sub/prefixF.foo',
'/C/prefixA.foo',
'/C/prefixD.foo',
'/C/prefixE.foo',
'/C/prefixF.foo',
'/D/prefixA',
'/D/prefixB',
'/D/prefixC',
'/D/prefixD',
'/D/prefixE',
'/D/prefixF',
'/E/prefixA.foo',
'/E/prefixD.foo',
'/E/prefixE.foo',
'/E/prefixF.foo',
'/prefixB.foo',
'/prefixD.foo',
'/prefixE.foo',
Expand Down Expand Up @@ -120,6 +152,9 @@ public function testGitExcludes()
'!/*/*/prefixF.foo',
'',
'refixD.foo',
'/C',
'D/prefixA',
'E/'
)));

// git does not currently support negative git attributes
Expand Down
4 changes: 2 additions & 2 deletions tests/Composer/Test/Package/Archiver/GitExcludeFilterTest.php
Expand Up @@ -29,8 +29,8 @@ public function testPatternEscape($ignore, $expected)
public function patterns()
{
return array(
array('app/config/parameters.yml', array('#(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml$#', false, false)),
array('!app/config/parameters.yml', array('#(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml$#', true, false)),
array('app/config/parameters.yml', array('#(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml/*.*$#', false, false)),
array('!app/config/parameters.yml', array('#(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml/*.*$#', true, false)),
);
}
}

0 comments on commit 21109ad

Please sign in to comment.