Skip to content

Commit

Permalink
ESDEV-4541 Exclude .git files
Browse files Browse the repository at this point in the history
Feedback/request to change from review.

There is no reason to copy .git files as they will not be used
for run-time.
  • Loading branch information
rezonanc-oxid committed Jun 13, 2017
1 parent f270589 commit d54c286
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 18 deletions.
38 changes: 37 additions & 1 deletion src/Installer/Package/AbstractPackageInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ abstract class AbstractPackageInstaller
const EXTRA_PARAMETER_FILTER_BLACKLIST = 'blacklist-filter';

/** Glob expression to filter all files, might be used to filter whole directory. */
const BLACKLIST_ALL_FILES = '**/*.*';
const BLACKLIST_ALL_FILES = '**/*';

/** Name of directory to be excluded for VCS */
const BLACKLIST_VCS_DIRECTORY = '.git';

/** Name of ignore files to be excluded for VCS */
const BLACKLIST_VCS_IGNORE_FILE = '.gitignore';

/** Glob filter expression to exclude VCS files */
const BLACKLIST_VCS_DIRECTORY_FILTER = self::BLACKLIST_VCS_DIRECTORY . DIRECTORY_SEPARATOR . self::BLACKLIST_ALL_FILES;

/** @var IOInterface */
private $io;
Expand Down Expand Up @@ -159,6 +168,33 @@ protected function getBlacklistFilterValue()
return $this->getExtraParameterValueByKey(static::EXTRA_PARAMETER_FILTER_BLACKLIST, []);
}

/**
* Get VCS glob filter expression
*
* @return array
*/
protected function getVCSFilter()
{
return [self::BLACKLIST_VCS_DIRECTORY_FILTER, self::BLACKLIST_VCS_IGNORE_FILE];
}

/**
* Combine multiple glob expression lists into one list
*
* @param array $listOfGlobExpressionLists E.g. [["*.txt", "*.pdf"], ["*.md"]]
*
* @return array
*/
protected function getCombinedFilters($listOfGlobExpressionLists)
{
$filters = [];
foreach ($listOfGlobExpressionLists as $filter) {
$filters = array_merge($filters, $filter);
}

return $filters;
}

/**
* @param string $messageToAsk
* @return bool
Expand Down
7 changes: 6 additions & 1 deletion src/Installer/Package/ModulePackageInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ public function update($packagePath)
*/
protected function copyPackage($packagePath)
{
$filtersToApply = [
$this->getBlacklistFilterValue(),
$this->getVCSFilter(),
];

CopyGlobFilteredFileManager::copy(
$this->formSourcePath($packagePath),
$this->formTargetPath(),
$this->getBlacklistFilterValue()
$this->getCombinedFilters($filtersToApply)
);
}

Expand Down
12 changes: 7 additions & 5 deletions src/Installer/Package/ShopPackageInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ShopPackageInstaller extends AbstractPackageInstaller
const SHOP_SOURCE_DIRECTORY = 'source';
const SHOP_SOURCE_SETUP_DIRECTORY = 'Setup';
const HTACCESS_FILTER = '**/.htaccess';
const SETUP_FILES_FILTER = self::SHOP_SOURCE_SETUP_DIRECTORY . '/**/*.*';
const SETUP_FILES_FILTER = self::SHOP_SOURCE_SETUP_DIRECTORY . AbstractPackageInstaller::BLACKLIST_ALL_FILES;

/**
* @return bool
Expand Down Expand Up @@ -92,15 +92,17 @@ private function copyPackage($packagePath)
*/
private function copyShopSourceFromPackageToTarget($packagePath)
{
$blacklistFilterWithHtAccess = array_merge(
$filtersToApply = [
$this->getBlacklistFilterValue(),
[self::HTACCESS_FILTER, self::SETUP_FILES_FILTER]
);
[self::HTACCESS_FILTER],
[self::SETUP_FILES_FILTER],
$this->getVCSFilter(),
];

CopyGlobFilteredFileManager::copy(
$this->getPackageDirectoryOfShopSource($packagePath),
$this->getTargetDirectoryOfShopSource(),
$blacklistFilterWithHtAccess
$this->getCombinedFilters($filtersToApply)
);
}

Expand Down
13 changes: 6 additions & 7 deletions src/Installer/Package/ThemePackageInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,16 @@ public function update($packagePath)
*/
protected function copyPackage($packagePath)
{
$filter = [Path::join($this->formAssetsDirectoryName(), AbstractPackageInstaller::BLACKLIST_ALL_FILES)];
$filterFromExtras = $this->getBlacklistFilterValue();

if (is_array($filterFromExtras)) {
$filter = array_merge($filter, $filterFromExtras);
}
$filtersToApply = [
[Path::join($this->formAssetsDirectoryName(), AbstractPackageInstaller::BLACKLIST_ALL_FILES)],
$this->getBlacklistFilterValue(),
$this->getVCSFilter(),
];

CopyGlobFilteredFileManager::copy(
$packagePath,
$this->formThemeTargetPath(),
$filter
$this->getCombinedFilters($filtersToApply)
);

$this->installAssets($packagePath);
Expand Down
50 changes: 50 additions & 0 deletions tests/Integration/Installer/Package/ModulePackageInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,56 @@ public function testBlacklistedFilesAreSkippedWhenABlacklistFilterIsDefined()
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/readme.txt');
}

public function testVCSFilesAreSkippedWhenNoBlacklistFilterIsDefined()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package', [
'metadata.php' => '<?php',
'.git/HEAD' => 'HEAD',
'.git/index' => 'index',
'.git/objects/ff/fftest' => 'blob',
'.gitignore' => 'git ignore',
]);

$installer = $this->getPackageInstaller('test-vendor/test-package', '1.0.0');
$installer->install($this->getVirtualFileSystemRootPath('vendor/test-vendor/test-package'));

$this->assertVirtualFileExists('source/modules/test-vendor/test-package/metadata.php');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.git/HEAD');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.git/index');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.git/objects/ff/fftest');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.gitignore');
}

public function testVCSFilesAreSkippedWhenABlacklistFilterIsDefined()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package', [
'metadata.php' => '<?php',
'module.php' => '<?php',
'readme.txt' => 'readme',
'.git/HEAD' => 'HEAD',
'.git/index' => 'index',
'.git/objects/ff/fftest' => 'blob',
'.gitignore' => 'git ignore',
]);

$installer = $this->getPackageInstaller('test-vendor/test-package', '1.0.0', [
'oxideshop' => [
'blacklist-filter' => [
'**/*.txt'
]
]
]);
$installer->install($this->getVirtualFileSystemRootPath('vendor/test-vendor/test-package'));

$this->assertVirtualFileExists('source/modules/test-vendor/test-package/metadata.php');
$this->assertVirtualFileExists('source/modules/test-vendor/test-package/module.php');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/readme.txt');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.git/HEAD');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.git/index');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.git/objects/ff/fftest');
$this->assertVirtualFileNotExists('source/modules/test-vendor/test-package/.gitignore');
}

public function testComplexCase()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package/custom-root', [
Expand Down
31 changes: 27 additions & 4 deletions tests/Integration/Installer/Package/ShopPackageInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protected function getPackageInstaller($packageName, $version = '1.0.0', $extra
{
$package = new Package($packageName, $version, $version);
$extra['oxideshop']['blacklist-filter'] = [
"Application/Component/**/*.*",
"Application/Controller/**/*.*",
"Application/Model/**/*.*",
"Core/**/*.*"
"Application/Component/**/*",
"Application/Controller/**/*",
"Application/Model/**/*",
"Core/**/*"
];
$package->setExtra($extra);

Expand Down Expand Up @@ -166,4 +166,27 @@ public function testShopInstallProcessDoesNotCopyFilteredClasses()
$this->assertVirtualFileNotExists('source/Application/Controller/Class.php');
$this->assertVirtualFileNotExists('source/Application/Component/Class.php');
}

public function testShopInstallProcessDoesNotCopyVCSFiles()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package/source', [
'index.php' => '<?php',
'.git/HEAD' => 'HEAD',
'.git/index' => 'index',
'.git/objects/ff/fftest' => 'blob',
'.gitignore' => 'git ignore',
]);

$installer = $this->getPackageInstaller('test-vendor/test-package');
$installer->install($this->getVirtualFileSystemRootPath('vendor/test-vendor/test-package'));

$this->assertVirtualFileEquals(
'vendor/test-vendor/test-package/source/index.php',
'source/index.php'
);
$this->assertVirtualFileNotExists('source/.git/HEAD');
$this->assertVirtualFileNotExists('source/.git/index');
$this->assertVirtualFileNotExists('source/.git/objects/ff/fftest');
$this->assertVirtualFileNotExists('source/.gitignore');
}
}
53 changes: 53 additions & 0 deletions tests/Integration/Installer/Package/ThemePackageInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,59 @@ public function testBlacklistedFilesAreSkippedWhenABlacklistFilterIsDefined()
$this->assertVirtualFileNotExists('source/out/test-package/style.pdf');
}

public function testVCSFilesAreSkippedWhenNoBlacklistFilterIsDefined()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package', [
'theme.php' => '<?php',
'.git/HEAD' => 'HEAD',
'.git/index' => 'index',
'.git/objects/ff/fftest' => 'blob',
'.gitignore' => 'git ignore',
]);

$installer = $this->getPackageInstaller('test-vendor/test-package', '1.0.0');
$installer->install($this->getVirtualFileSystemRootPath('vendor/test-vendor/test-package'));

$this->assertVirtualFileExists('source/Application/views/test-package/theme.php');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.git/HEAD');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.git/index');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.git/objects/ff/fftest');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.gitignore');
}

public function testVCSFilesAreSkippedWhenABlacklistFilterIsDefined()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package', [
'theme.php' => '<?php',
'theme.txt' => 'txt',
'.git/HEAD' => 'HEAD',
'.git/index' => 'index',
'.git/objects/ff/fftest' => 'blob',
'.gitignore' => 'git ignore',
'out/style.css' => 'css',
'out/style.pdf' => 'PDF',
]);

$installer = $this->getPackageInstaller('test-vendor/test-package', '1.0.0', [
'oxideshop' => [
'blacklist-filter' => [
'**/*.txt',
'**/*.pdf',
]
]
]);
$installer->install($this->getVirtualFileSystemRootPath('vendor/test-vendor/test-package'));

$this->assertVirtualFileExists('source/Application/views/test-package/theme.php');
$this->assertVirtualFileNotExists('source/Application/views/test-package/theme.txt');
$this->assertVirtualFileExists('source/out/test-package/style.css');
$this->assertVirtualFileNotExists('source/out/test-package/style.pdf');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.git/HEAD');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.git/index');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.git/objects/ff/fftest');
$this->assertVirtualFileNotExists('source/Application/views/test-package/.gitignore');
}

public function testComplexCase()
{
$this->setupVirtualProjectRoot('vendor/test-vendor/test-package', [
Expand Down

0 comments on commit d54c286

Please sign in to comment.