Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

How to apply a patch: Difference between revisions

From MoodleDocs
(Improve documentation a bit)
Line 17: Line 17:
     c:\bin\patch.exe -p1 < mynewpatch.diff
     c:\bin\patch.exe -p1 < mynewpatch.diff


* You should get an output similar to this:
:The number after <tt>'-p'</tt> option can vary depending on the patch file, as it depends on the way the patch file was generated. Have a look at the [http://www.rt.com/man/patch.1.html 'patch' utility manual page ] to see how the <tt>'-p'</tt> option works. You could also have a look at this [http://www.linuxtutorialblog.com/post/introduction-using-diff-and-patch-tutorial diff and patch tutorial].
* You should get an output similar to this (the names and quantity of patched files vary from patch to patch):


     patching file admin/settings/security.php
     patching file admin/settings/security.php
Line 26: Line 27:
     patching file user/edit.php
     patching file user/edit.php
     Hunk #1 succeeded at 430 (offset 2 lines).
     Hunk #1 succeeded at 430 (offset 2 lines).
:If you get any <tt>'Hunk #n succeeded...'</tt> messages, the patch was applied correctly although at different line numbers than the original file. In this case the 'patch' command will have created an additional file for each of the files where the hunk was applied at a different offset, that is named like the original file with the additional extension <tt>.orig</tt>. You can delete those files safely.
:If you get any <tt>'Hunk #n failed...'</tt> messages, the patch could not be applied correctly. In this case the 'patch' command will have created two additional files for each of the files where the hunk was not applied correctly, called:
:* <tt>original-file-name.orig</tt>&nbsp; &nbsp; This is the original file before the patch was applied, just like above.
:* <tt>original-file-name.rej&nbsp;</tt>&nbsp; &nbsp; This file contains the hunks that could not be applied correctly, so you can inspect them.
: In this case, unless you know how to fix the failed hunks by hand, you should delete the partially patched file (the one with the original file name) and rename 'original-file-name.orig' to 'original-file-name', to restore the original file. You should also delete the .rej file.


==Apply a Patch in Linux using "patch"==
==Apply a Patch in Linux using "patch"==

Revision as of 13:56, 28 August 2008

Introduction

This page explains how you can apply a patch file. Patch is a standard format, and there are many options for how to apply one. Pick the one that is easiest for you.

Apply a Patch in Windows using gnuwin32

  • Download and extract patch for windows from sourceforge I placed the patch.exe binary in C:\bin
  • Download and extract Moodle somewhere. eg: C:\moodle
  • Download the patch file and place it in the same directory you put Moodle (C:\moodle\password-policy-17.diff)
  • Open the patch file with Wordpad, and click 'File' >> 'Save as...', choose a different name for the file eg ('mynewpatch.diff') and "Save as type" >> 'Text Document - MS-DOS Format'
  • Open up a command text window, and type:
   cd \moodle
   c:\bin\patch.exe -p1 < mynewpatch.diff
The number after '-p' option can vary depending on the patch file, as it depends on the way the patch file was generated. Have a look at the 'patch' utility manual page to see how the '-p' option works. You could also have a look at this diff and patch tutorial.
  • You should get an output similar to this (the names and quantity of patched files vary from patch to patch):
   patching file admin/settings/security.php
   patching file lang/en_utf8/admin.php
   patching file lib/moodlelib.php
   patching file login/change_password.php
   patching file login/signup.php
   patching file user/edit.php
   Hunk #1 succeeded at 430 (offset 2 lines).
If you get any 'Hunk #n succeeded...' messages, the patch was applied correctly although at different line numbers than the original file. In this case the 'patch' command will have created an additional file for each of the files where the hunk was applied at a different offset, that is named like the original file with the additional extension .orig. You can delete those files safely.
If you get any 'Hunk #n failed...' messages, the patch could not be applied correctly. In this case the 'patch' command will have created two additional files for each of the files where the hunk was not applied correctly, called:
  • original-file-name.orig    This is the original file before the patch was applied, just like above.
  • original-file-name.rej     This file contains the hunks that could not be applied correctly, so you can inspect them.
In this case, unless you know how to fix the failed hunks by hand, you should delete the partially patched file (the one with the original file name) and rename 'original-file-name.orig' to 'original-file-name', to restore the original file. You should also delete the .rej file.

Apply a Patch in Linux using "patch"

use something like: patch -p1 < patchfile.diff see here for more details on using Patch in Linux

See Also