0

I attempted to make a patch using Making a Drupal patch with Git and ran into one issue after creating the patch. For some reason, I cannot get the proper location to be stored in the patch.

How can I get the desired results in the patch?

Issue

  • the issue is that it is setting diff --git "a/docroot/modules/contrib/video_embed_vidyard/src..."

Command used to generate the patch:

git diff <commit#1> <commit#2> > patch-name.patch

Current results:

diff --git a/docroot/modules/contrib/video_embed_vidyard/src/Plugin/video_embed_field/Provider/Vidyard.php b/docroot/modules/contrib/video_embed_vidyard/src/Plugin/video_embed_field/Provider/Vidyard.php
index 94a7dc26b..4de97deb7 100644
--- a/docroot/modules/contrib/video_embed_vidyard/src/Plugin/video_embed_field/Provider/Vidyard.php
+++ b/docroot/modules/contrib/video_embed_vidyard/src/Plugin/video_embed_field/Provider/Vidyard.php

Desired results:

diff --git a/src/Plugin/video_embed_field/Provider/Vidyard.php 
b/src/Plugin/video_embed_field/Provider/Vidyard.php
index 94a7dc2..be635ad 100644
--- a/src/Plugin/video_embed_field/Provider/Vidyard.php
+++ b/src/Plugin/video_embed_field/Provider/Vidyard.php
  • I want to be able to generate a/src/.. instead of a/docroot/modules/contrib/video_embed_vidyard/src
  • Using git diff, make sure to also use the current dev version of the module as git repository (e.g. clone from the Drupal git repositories) and create your diff from within the cloned module path. (cd docroot/modules/contribute/video_embed_vidyard && git diff). – Mario Steinitz Mar 12 '18 at 23:58
3

The command git diff always creates a diff (patch) for the current repository you are working with. If you want to create a patch for a certain module, but get a diff with full paths including your Drupal root, it's very likely that you are either

(a) not within the directory of the module's Git repository, or

(b) your module is not a git repository, thus Git is using the next repository it finds while traversing up the folders.

How to fix it?

If you want to create a diff using git diff,

(1) make sure you are using a version of the module that has been cloned from a Git repository. When using Composer for dependency management and your module is a contrib module, you can do so by requiring the dev version of the module, e.g. with your video_embed_vidyard module:

composer require "drupal/video_embed_vidyard:1.x-dev"

Make sure to backup your applied changes first to another location, as running the above command will most likely overwrite them; then re-apply them before proceeding with step (2).

If you are NOT using Composer for dependency management, you can manually clone the module. Every contrib module has a Development section within the sidebar of its project page. Locate the Browse code repository link.

enter image description here

On the bottom of the repository listing, you'll find the public clone URL. For your module, the clone command would be:

git clone https://git.drupal.org/project/video_embed_vidyard.git

You might have to switch to the correct branch after cloning, as some modules still use the 7.x branch as default or did not set any.

(2) make sure to run git diff from within the module root (Git repository root of the module), not the Drupal root:

cd docroot/modules/contrib/video_embed_vidyard
git diff > ../video_embed_vidyard.patch

This will save your patch in your contrib folder. If you intend to send this patch to the Drupal issue queue of this module, you should also include the issue number in the name of the patch file.

(3) [optional] once again, if you are using Composer for dependency management (highly suggested for Drupal 8), then post your patch to the drupal.org issue queue and also enable patching (cweagans/composer-patches) and include the patch in your composer.json. This ensures your changes being applied to your version of the module every time you are running a Composer install (until your patch was approved by the maintainers and merged with the module's code base).

|improve this answer|||||
  • @MarioSteinitiz, silly me, i was doing the git diff command in the wrong repository. After down your steps 1-2, it got it to show properly. thanks – usernameabc Mar 13 '18 at 2:17
  • only thing i would add to your instructions is that since I am not committing i would have to do git diff --staged > ../video_embed_vidyard.ptach – usernameabc Mar 13 '18 at 2:42
4

Actually, there is a fairly easy way to generate a patch for a certain path with --relative.

So in your case, just run git diff --relative=docroot/modules/contrib/video_embed_vidyard.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.