Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install patches from local file #146

Closed
joum opened this issue Aug 4, 2017 · 14 comments
Closed

Install patches from local file #146

joum opened this issue Aug 4, 2017 · 14 comments

Comments

@joum
Copy link

joum commented Aug 4, 2017

I created a .patch file for a Drupal module that I have been using, and I would like to have it versioned with my codebase, but not publicly online. That being said, I would like to have the file stored locally and use a similar syntax to what is already possible, but referring a local file instead of an URL. Is this possible?

@cweagans
Copy link
Owner

cweagans commented Aug 4, 2017

Yes, this is possible. Instead of a URL, you can specify a path to your patch file relative to the directory that your composer.json is in. For instance, if the patch file is in the same directory as your composer.json, the URL would be either 'patchname.patch' or './patchname.patch'.

@cweagans cweagans closed this as completed Aug 4, 2017
@cweagans
Copy link
Owner

cweagans commented Aug 4, 2017

(For reference, the plugin just uses file_get_contents() under the hood, so anything you can pass as the first argument will be valid for this plugin)

@joum
Copy link
Author

joum commented Aug 8, 2017

@cweagans Thank you for your reply. Is it possible that some folder permissions interfere with this process? I created a patches directory next to my composer.json file and then I referenced a .patch file like you mentioned above and composer terminated with a file not found exception.

I tried debugging your module for a bit and found out it was breaking in the getAndApplyPatch function. The eventDispatchertriggered for every patch I had, but then the file_exists never got the real filename, and then advanced to the download option, which in turn failed because it isn't a valid URI.

I eventually found another way to solve my problem, but if it's helpful I could open an issue with more details and the error messages.

@cweagans
Copy link
Owner

cweagans commented Aug 8, 2017

If you can post a composer.json that reproduces the problem here, I can take a look.

@milkovsky
Copy link

Change your patch extension to txt. Example:

"extra": {
        "patches": {
            "drupal/views_infinite_scroll": {
                "Integrate with Ajax Assets Plus" : "patches/foo-bar.patch.txt"
            }
        }
    }

@marklabrecque
Copy link

Adding .txt is what fixed it for me. Thanks @milkovsky !

marklabrecque added a commit to marklabrecque/drupal-project that referenced this issue Oct 11, 2018
This would have saved me a lot of time. This fix is referenced here cweagans/composer-patches#146
@uberhacker
Copy link

The .txt extension trick didn't work for me. Why would an extension matter?

@uberhacker
Copy link

@cweagans: Can this issue be reopened? The current version is not accepting local patches named .patch or .txt.

@marklabrecque
Copy link

Still works fine for me. Please ensure your path is setup correctly to reference from the project root for composer to find the file in question

@uberhacker
Copy link

I don't get a file not found message. It just doesn't apply. FWIW, this is a Drupal core patch. I still haven't received an answer to my question about the .txt extension. That doesn't make any sense.

@uberhacker
Copy link

To reproduce this, try creating a core patch and install it from a local file instead of a remote url.

@marklabrecque
Copy link

marklabrecque commented Oct 21, 2018

Can you paste your composer.json code into a comment here and we might be able to track down the issue?

@uberhacker
Copy link

uberhacker commented Oct 21, 2018

I figured out my issue. Apparently, a simple git diff > /path/to/file.patch to create the patch is not enough. After I created the patch via git diff --no-prefix > /path/to/file.patch, it then applied successfully. Hopefully, this helps somebody else that has been frustrated by this issue.

@loopy3025
Copy link

Fixing the path in the patch file worked for me. In my case, I was trying to patch a Drupal project. When I created the patch file, it used the path relative to where I was in the project. When applying patches, composer in a Drupal project uses a different path.

As created:

diff --git a/docroot/core/lib/Drupal/Core/Config/StorageComparer.php b/docroot/core/lib/Drupal/Core/Config/StorageComparer.php
index 5110111aa..5e3f4fbad 100644
--- a/docroot/core/lib/Drupal/Core/Config/StorageComparer.php
+++ b/docroot/core/lib/Drupal/Core/Config/StorageComparer.php

Changes needed for composer to apply:

diff --git web/core/lib/Drupal/Core/Config/StorageComparer.php web/core/lib/Drupal/Core/Config/StorageComparer.php
index 5110111aa..5e3f4fbad 100644
--- web/core/lib/Drupal/Core/Config/StorageComparer.php
+++ web/core/lib/Drupal/Core/Config/StorageComparer.php

rwalkerands added a commit to rwalkerands/x1-custom-module-x1 that referenced this issue Aug 25, 2021
As per cweagans/composer-patches#146 ,
try renaming the patches to use a .txt suffix, to see if that
works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants