1
0
Fork 0

Updated the regexp and added more test cases.

pull/2769/head
Sandy Pleyte 2014-02-28 11:43:28 +01:00
parent 21109ada22
commit 1d51e54a31
3 changed files with 38 additions and 16 deletions

View File

@ -136,12 +136,15 @@ abstract class BaseExcludeFilter
if (strlen($rule) && $rule[0] === '/') {
$pattern .= '^/';
$rule = substr($rule, 1);
} elseif (false === strpos($rule, '/') || strlen($rule) - 1 === strpos($rule, '/')) {
} elseif (strlen($rule) - 1 === strpos($rule, '/')) {
$pattern .= '^/';
$rule = substr($rule, 0, -1);
} elseif (false === strpos($rule, '/')) {
$pattern .= '/';
}
// remove delimiters as well as caret (^) and dollar sign ($) from the regex
$pattern .= substr(Finder\Glob::toRegex($rule), 2, -2) . '/*.*$';
$pattern .= substr(Finder\Glob::toRegex($rule), 2, -2) . '(?=$|/)';
return array($pattern . '#', $negate, false);
}

View File

@ -58,12 +58,10 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
'D/prefixD',
'D/prefixE',
'D/prefixF',
'E/prefixA.foo',
'E/prefixB.foo',
'E/prefixC.foo',
'E/prefixD.foo',
'E/prefixE.foo',
'E/prefixF.foo',
'/E/subtestA.foo',
'/F/subtestA.foo',
'/G/subtestA.foo',
'/H/subtestA.foo',
'toplevelA.foo',
'toplevelB.foo',
'prefixA.foo',
@ -72,6 +70,10 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
'prefixD.foo',
'prefixE.foo',
'prefixF.foo',
'parameters.yml',
'parameters.yml.dist',
'!important!.txt',
'!important_too!.txt'
);
foreach ($fileTree as $relativePath) {
@ -100,6 +102,8 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
$this->finder = new ArchivableFilesFinder($this->sources, $excludes);
$this->assertArchivableFiles(array(
'/!important!.txt',
'/!important_too!.txt',
'/A/prefixA.foo',
'/A/prefixD.foo',
'/A/prefixE.foo',
@ -119,10 +123,12 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
'/D/prefixD',
'/D/prefixE',
'/D/prefixF',
'/E/prefixA.foo',
'/E/prefixD.foo',
'/E/prefixE.foo',
'/E/prefixF.foo',
'/E/subtestA.foo',
'/F/subtestA.foo',
'/G/subtestA.foo',
'/H/subtestA.foo',
'/parameters.yml',
'/parameters.yml.dist',
'/prefixB.foo',
'/prefixD.foo',
'/prefixE.foo',
@ -154,7 +160,12 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
'refixD.foo',
'/C',
'D/prefixA',
'E/'
'E',
'F/',
'G/*',
'H/**',
'parameters.yml',
'\!important!.txt'
)));
// git does not currently support negative git attributes
@ -195,9 +206,15 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
'# comments',
'',
'^prefixD.foo',
'D/prefixA',
'parameters.yml',
'\!important!.txt',
'E',
'F/',
'syntax: glob',
'prefixF.*',
'B/*',
'H/**',
)));
$this->finder = new ArchivableFilesFinder($this->sources, array());
@ -208,7 +225,9 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
'hg archive archive.zip'
);
array_shift($expectedFiles); // remove .hg_archival.txt
// Remove .hg_archival.txt from the expectedFiles
$archiveKey = array_search('/.hg_archival.txt', $expectedFiles);
array_splice($expectedFiles, $archiveKey, 1);
$this->assertArchivableFiles($expectedFiles);
}

View File

@ -29,8 +29,8 @@ class GitExcludeFilterTest extends \PHPUnit_Framework_TestCase
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)),
);
}
}