Note:

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

How to create a patch: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 42: Line 42:


[http://winmerge.org/ WinMerge] is a nice windows GUI for comparing folders. In this sense it is like the original command-line 'diff' program. You need a copy of 'standard_moodle' and 'my_moodle'. Use '''File -> Open...''' to open the two versions for comparison. This will give you a nice view of what you have changed. Then do '''Tools -> Generate patch ...'''. In the dialogue box, make sure you select Style: Unified in the Format box.
[http://winmerge.org/ WinMerge] is a nice windows GUI for comparing folders. In this sense it is like the original command-line 'diff' program. You need a copy of 'standard_moodle' and 'my_moodle'. Use '''File -> Open...''' to open the two versions for comparison. This will give you a nice view of what you have changed. Then do '''Tools -> Generate patch ...'''. In the dialogue box, make sure you select Style: Unified in the Format box.
==See Also==
==See Also==
* [[How_to_apply_a_patch]]
* [[How_to_apply_a_patch]]
* [[Patch]]

Revision as of 03:31, 12 September 2008

If you have made some changes to the code that you would like to share with the community, particularly if you want to send them to one of the core developers for possible inclusion in Moodle Core, it is very helpful if you can provide them as a patch file. Sometimes also called a diff file.

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

Note, I have not been able to test most of these instructions. They are about right, but I am hoping that as people use them, they will fill in any gaps, correct any details, and so on.Tim Hunt 08:40, 25 June 2007 (CDT)

Creating a patch using diff

diff is the a linux command line program, and is where patch files originated. It requires that you have two copies of the code, one with your changes, and one without. Suppose these two copies are in folders called 'standard_moodle' and 'my_moodle' which are subdirectories of the current folder. Then to create the patch, type:

diff -Naur standard_moodle my_moodle > patch.txt

Creating a patch using CVS (command line)

It is easier if you are using CVS to manage your development, because you don't need to keep the copy of 'standard_moodle'. CVS takes care of that for you. In you workspace (sandbox) type:

cvs diff -uN > patch.txt

If you have unversioned files to include in your patch, you will notice that the above command simply adds the file's name to the top of your patch, prefixed with a question mark. This is because your new file is not tagged for adding to the repository. Just do

cvs add newfile

Then

cvs diff -uNa > patch.txt

This should add the correct code to the patch, so that someone applying the patch to their working copy will have a new file created at the right place (hopefully!).

If your patch, for some reason, contains a lot of white space changes in many files, you might want to add -Bbw to the diff call. Make sure these changes are really not significant (like adding or removing a space at the end of a line - editors like Eclipse sometimes do this automatically). This can make a patch a lot smaller, and thus easier to review. The complete call would then be

cvs diff -uNawbB > patch.txt

Creating a patch using Tortoise CVS

Tortoise CVS is a Windows GUI front end for CVS. To create a patch, right-click on a folder in CVS, and choose CVS -> Make patch ... from the context menu.

Creating a patch using Eclipse

See Setting_up_Eclipse#Creating_a_patch. Eclipse makes creating patches really easy, once you have got it set up correctly.

Creating a patch using WinMerge

WinMerge is a nice windows GUI for comparing folders. In this sense it is like the original command-line 'diff' program. You need a copy of 'standard_moodle' and 'my_moodle'. Use File -> Open... to open the two versions for comparison. This will give you a nice view of what you have changed. Then do Tools -> Generate patch .... In the dialogue box, make sure you select Style: Unified in the Format box.

See Also