composer-patches icon indicating copy to clipboard operation
composer-patches copied to clipboard

Allow applying patches that affect test code when test code is missing

Open AdamPS opened this issue 4 years ago • 2 comments

This change is a pre-requisite for the Drupal issue Exclude test files from release packages - see there for more background.

This patching tool needs to be flexible about how to discover which directories to exclude - presumably using plug-ins and events. There are two main options in discussion at preset:

  1. Excluded with gitattributes. This is a generic, widespread approach that this tool could implement directly.
  2. Excluded with drupal/core-vendor-hardening. This is a very specific mechanism so presumably the vendor hardening code should integrate a plug-in for this patching tool.

When applying patches, this patching tool would next check if the excluded directories exists, and if so apply the patch as normal.

For any directories that are missing, then this patching tool needs to exclude them from the patch. When using git it's simple, using the --exclude option. With other tools it's more tricky - patch doesn't have a corresponding option. As a fallback this patching tool could manipulate the patch to remove the test directories from it, but this is less desirable because it requires a detailed understanding of the full range of valid syntaxes for patch files.

AdamPS avatar Jan 08 '20 10:01 AdamPS

With #294 merged git should work for all patches if installed. The patch command can be left as it is for now as it will be then only as a fallback.

So submit a PR with git apply command fix, the git apply check will probably need the fix too.

mvorisek avatar Jan 13 '20 11:01 mvorisek

Instead of auto-detection, the patch definition could provide a config option where an excluded path can be specified, which could be passed through to git apply --exclude at https://github.com/cweagans/composer-patches/blob/a18d1ca38ae09d16aa21846f60649d99d6775639/src/Plugin/Patches.php#L408

Current the config layout doesn't provide a handy place for specifying this, however.

sminnee avatar Jul 27 '20 05:07 sminnee

I've made a note to think through this for 2.x. My first inclination is to say "Fix your patch" (or use 'preferred-install': 'source'), but I can see how this would be useful.

cweagans avatar Feb 07 '23 21:02 cweagans

Great thanks

AdamPS avatar Feb 08 '23 17:02 AdamPS