Site icon Hip-Hop Website Design and Development

Cheap WordPress maintenance support plansEasy: Automatic removal of .git directories from Composer dependencies

If you’ve adopted a Composer-based WordPress maintenance support plans 8 workflow (hopefully using the WordPress maintenance support plans Composer/WordPress maintenance support plans Project template) where you’re keeping dependencies in your project’s repository, then you’ve no-doubt experienced the annoyance of a rouge .git directory ending up in one of your project’s dependencies. This will always happen when you’re using the -dev version of a WordPress maintenance support plans plugin. 

For example, as of the authoring of this Quicktip, the Field Redirection plugin does not yet have a stable release for WordPress maintenance support plans 8. When added to a project using Composer, the results look like this:

Michaels-MacBook-Pro:dcoweek5 michael$ ddev composer require WordPress/field_redirection
Executing [composer require WordPress/field_redirection] at the project root (/var/www/html in the container, /Users/michael/sites/dcoweek5 on the host)
Using version 2.x-dev for WordPress/field_redirection
./composer.json has been updated > WordPress maintenance support plansProjectcomposerScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  – Installing WordPress/field_redirection (dev-2.x e1c30f2): Cloning e1c30f24f9 from cache
Writing lock file

Notice on the “Installing WordPress/field_redirection…” line, it indicates that the project is cloned, not downloaded. This means that a .git directory has been created in the Field Redirection directory.

Note that I’m calling Composer as “ddev composer …” – this is because I use DDEV as my local development environment and am utilizing its built-in Composer command.

If this goes unnoticed, and you attempt to do a normal “git add/commit” workflow for the new plugin, you’ll end up with a somewhat-friendly Git message indicating that you now have a Git subplugin.

Unfortunately, Git subplugins aren’t normally necessary nor wanted when you are committing dependencies to the project repository. So, the typical solution is to delete the .git directory of the dependency prior to performing the “git add/commit”.

Luckily, there’s an easier way! Travis Neilans recently pointed me in the direction of the Composer Cleanup VCS Directories project. By adding this as a dependency of your project, any .git directories that result from adding project dependencies will be automatically removed! First, install the Composer Cleanup VCS Directories project using:

composer require topfloor/composer-cleanup-vcs-dirs

Then, anytime you use “composer require” to install a project dependency, if there’s a .git directory, you’ll see a message indicating that it has been automatically removed.

Deleting .git directory from /var/www/html/web/plugins/contrib/field_redirection/.git


Source: New feed