I was trying to google the method to install a patch file, but the results keep returning as "issues encountered while patching", which isn't what I am looking for.

I was wondering how to use drush to install a patch file?

More specifically, I'm currently encountering a Drupal for Facebook module issue, about the q variable.

One of the answers suggests installing a patch file. How do i install this patch file from the command line?

  • possible duplicate.. – AjitS Aug 31 '12 at 13:49
  • i am aware of that question. But there still isn't any direct answer on how to apply a patch file. – He Hui Aug 31 '12 at 13:53

The instructions on how to apply a patch are given, for that module, on http://drupal.org/project/fb/git-instructions.

First off, git patches can be applied to a git repository you need to locally clone, which means you need to execute the following command:

git clone --recursive --branch master http://git.drupal.org/project/fb.git

Then you copy the patch in the fb directory created from the previous command, and execute the following one:

cd fb
git apply -v fb_stream.admin_.inc_.patch

Once the patch is applied, you delete it.

rm  fb_stream.admin_.inc_.patch

This assume the patch is applied to the development snapshot. If this is not the case, then somebody needs to provide a patch for the development snapshot.

Anyway, the patch doesn't apply. If you try applying it, you will get the following error:

Checking patch Users/johnrobens/Downloads/fb/fb_stream.admin.inc... error: Users/johnrobens/Downloads/fb/fb_stream.admin.inc: No such file or directory

You need to change the patch to the following one, to avoid that error.

--- fb_stream.admin.inc
+++ fb_stream.admin.inc
@@ -1,5 +1,6 @@

  * Form callback for general settings.
@@ -19,7 +20,8 @@
             '%user_name' => $from['name'],
             '%token' => $token,
-    } catch (Exception $e) {
+    }
+    catch (Exception $e) {
       fb_log_exception($e, t('Unable to query graph with fb_stream token.'));
       drupal_set_message(t('There was an error using the current access token, %token.  Consider generating a new token.', array(
             '%token' => $token,
@@ -29,7 +31,7 @@

   if (!empty($_REQUEST['code']) && empty($_POST)) {
     // Send user to this URL after token is generated.
-    $redirect_uri = url(request_path(), array(
+    $redirect_uri = url($_REQUEST['q'], array(
       'absolute' => TRUE,
       'query' => array(
         'client_id' => $_REQUEST['client_id'],
@@ -59,7 +61,7 @@
   foreach (fb_get_all_apps() as $fb_app) {
     // Send user to this URL after token is generated.
-    $redirect_uri = url(request_path(), array(
+    $redirect_uri = url($_REQUEST['q'], array(
       'absolute' => TRUE,
       'query' => array(
         'client_id' => $fb_app->id,
@@ -92,7 +94,7 @@
       'client_id' => $app_id,
       'client_secret' => $fb_app->secret,
       'code' => $code,
-      'redirect_uri' => $redirect_uri,
+                  'redirect_uri' =>$redirect_uri,
   $http = drupal_http_request($path);

Even if you do that, you would get the error, "patch doesn't apply." I tried applying it to the development snapshot 7.x-3.x (the master branch for git).

  • is anything supposed to show up after "git apply -v [patchname.patch] ? – He Hui Aug 31 '12 at 13:57
  • As far as I recall, git apply doesn't shown any message when it successfully applies the patch. – kiamlaluno Aug 31 '12 at 14:32

Here's really good explanation of applying patches with git. If you haven't got git installed there's some links to instructions for various different platforms here.

Beyond that, make sure you are patching the correct version of the code otherwise you may get errors when applying the patch.

Some more general info on git can be found in the Pro Git book.

  • Also, give the drush issue queue commands a try! drupal.org/project/drush_iq – greg_1_anderson Aug 31 '12 at 13:47
  • That's interesting, hadn't come across that before! – splatio Aug 31 '12 at 13:48
  • @splatio how can you apply a patch to a module from a patch folder to the contrib module – jelly46 Jul 21 '16 at 13:27

Without details regarding your environment, patching details would be very difficult to give and would likely not be appropriate for drupal.stackexchange.com. Drupal has a bit of documentation though that my lead you in the right direction.


In the simplest form using patch patch -p1 < path/file.patch or if you use git git apply path/file.patch

  • 1
    i did try both; using git apply did not change anything. Using patch -p1< path/file.patch returns error, something about HUNK failing. – He Hui Aug 31 '12 at 13:52
  • @Citricguy so if i place the patch in a patch file first to patch the module from the patch file is it patch -p1 < path/file.patch – jelly46 Jul 21 '16 at 15:23

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.