Skip to content

Commit

Permalink
Merge pull request #2 from AydinHassan/gitignore-improvements
Browse files Browse the repository at this point in the history
Only remove files which are being uninstalled from the gitignore
  • Loading branch information
AydinHassan committed Dec 10, 2014
2 parents 8afde61 + e5a5818 commit a3b83e2
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 193 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Available configuration

* `excludes` - An array of files to not copy when installing the core, useful if local overrides are necessary, or you want to track a `.htaccess`.
* `ignore-directories` - An array of folders to group ignores together to make the core `.gitignore` smaller.
* `git-ignore-append` - Defaults to `false`. Whether to append to the `.gitignore` in the `magento-root-dir` folder. Otherwise it will be wiped out on each deploy.
* `git-ignore-append` - Defaults to `true`. Whether to append to the `.gitignore` in the `magento-root-dir` folder. If false it will be wiped out on each deploy.

Example configuration:

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "aydin-hassan/magento-core-composer-installer",
"type": "composer-plugin",
"require": {
"composer-plugin-api": "~1.0"
"composer-plugin-api": "~1.0",
"mikey179/vfsStream": "~1.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "~1.5",
Expand Down
51 changes: 45 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions src/CoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CoreInstaller
/**
* @var GitIgnore
*/
protected $gitIgnore = true;
protected $gitIgnore;

/**
* @var array
Expand All @@ -27,7 +27,7 @@ class CoreInstaller
* @param array $excludes
* @param GitIgnore $gitIgnore
*/
public function __construct(array $excludes, GitIgnore $gitIgnore = null)
public function __construct(array $excludes, GitIgnore $gitIgnore)
{
$this->gitIgnore = $gitIgnore;
$this->excludes = $excludes;
Expand Down Expand Up @@ -64,10 +64,7 @@ public function install($source, $destination)
}

copy($item, $destinationFile);

if ($this->gitIgnore) {
$this->gitIgnore->addEntry($iterator->getSubPathName());
}
$this->gitIgnore->addEntry($iterator->getSubPathName());
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/CoreManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public function installCore(PackageEvent $event)

if ($package->getType() === $this->type) {
$options = new Options($this->composer->getPackage()->getExtra());

$gitIgnore = new GitIgnore(
sprintf("%s/.gitignore", $options->getMagentoRootDir()),
$options->getIgnoreDirectories(),
Expand Down Expand Up @@ -220,9 +219,13 @@ public function uninstallCore(PackageEvent $event)
}

if ($package->getType() === $this->type) {
$options = new Options($this->composer->getPackage()->getExtra());
$gitIgnore = new GitIgnore(sprintf("%s/.gitignore", $options->getMagentoRootDir()), array(), false);
$unInstaller = new CoreUnInstaller($this->filesystem, $gitIgnore);
$options = new Options($this->composer->getPackage()->getExtra());
$gitIgnore = new GitIgnore(
sprintf("%s/.gitignore", $options->getMagentoRootDir()),
$options->getIgnoreDirectories(),
$options->appendToGitIgnore()
);
$unInstaller = new CoreUnInstaller($this->filesystem, $gitIgnore);
$this->removeCorePackage($package, $unInstaller, $options);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/CoreUnInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class CoreUnInstaller
{

/**
* @var Filesystem
* @var GitIgnore
*/
protected $fileSystem;
protected $gitIgnore;

/**
* @var GitIgnore
* @var Filesystem
*/
protected $gitIgnore;
protected $fileSystem;

/**
* @param Filesystem $fileSystem
* @param GitIgnore $gitIgnore
*/
public function __construct(Filesystem $fileSystem, GitIgnore $gitIgnore)
{
Expand All @@ -52,6 +53,7 @@ public function unInstall($source, $destination)
$destinationFile = sprintf("%s/%s", $destination, $iterator->getSubPathName());

if (!file_exists($destinationFile)) {
$this->gitIgnore->removeEntry($iterator->getSubPathName());
continue;
}

Expand All @@ -65,8 +67,9 @@ public function unInstall($source, $destination)
}

$this->fileSystem->unlink($destinationFile);
$this->gitIgnore->removeEntry($iterator->getSubPathName());
}

$this->gitIgnore->wipeOut();
$this->gitIgnore->removeIgnoreDirectories();
}
}
23 changes: 22 additions & 1 deletion src/GitIgnore.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GitIgnore
* @param array $directoriesToIgnoreEntirely
* @param bool $gitIgnoreAppend
*/
public function __construct($fileLocation, array $directoriesToIgnoreEntirely, $gitIgnoreAppend = false)
public function __construct($fileLocation, array $directoriesToIgnoreEntirely, $gitIgnoreAppend = true)
{
$this->gitIgnoreLocation = $fileLocation;

Expand Down Expand Up @@ -69,6 +69,27 @@ public function addEntry($file)
$this->hasChanges = true;
}

/**
* @param string $file
*/
public function removeEntry($file)
{
if (isset($this->lines[$file])) {
unset($this->lines[$file]);
$this->hasChanges = true;
}
}

/**
* Remove all the directories to ignore
*/
public function removeIgnoreDirectories()
{
foreach ($this->directoriesToIgnoreEntirely as $directory) {
$this->removeEntry($directory);
}
}

/**
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Options
*
* @var bool
*/
protected $appendToGitIgnore = false;
protected $appendToGitIgnore = true;

/**
* Magento Root Directory
Expand Down
Loading

0 comments on commit a3b83e2

Please sign in to comment.