Common problems

Last modified: February 19, 2008 - 03:55

UNIX vs. Windows end-of-line encoding

Text files originating from UNIX systems use a single linefeed character (LF) to mark the end of a line, whereas Windows systems use a carriage return followed by a linefeed (CRLF).

The GnuWin32 patch program may crash on a patchfile with Unix end-of-line encoding throwing the error "Assertion failed: hunk, file [path]/patch.c, line 339".

Most patches downloaded from drupal.org are UNIX text files. When you use patch on Windows, you need to convert line-endings using a unix2dos utility or a decent text-editor.

One way to do this is to open the file with WORDPAD, choose "Save as" and select as type Text document.

Patch can't find the target file

This usually means that you are either executing patch in the wrong directory or that the patch was made relative to another directory. Open the patchfile and locate the lines describing the changed files to determine the path:

--- modules/codefilter/codefilter.module Tue Mar 28 15:04:48 2006
+++ modules/codefilter/codefilter.module Sun Apr 23 15:51:32 2006

The above patch appears to be made relative to the drupal root directory so you can execute the following command from the Drupal root:

patch -p0 < file.patch

The number after -p determines the number of path elements that should be ignored. This is very useful when you need to apply a patch that was made against an old and new directory:

--- olddir/modules/codefilter/codefilter.module Tue Mar 28 15:04:48 2006
+++ newdir/modules/codefilter/codefilter.module Sun Apr 23 15:51:32 2006

You can apply this patch from the Drupal root by stripping the first path element; 'olddir' / 'newdir':

patch -p1 < file.patch

As a fast solution you can

sinasalek - January 17, 2008 - 15:12

As a fast solution you can use following command for applying the patch (end line safe)

patch {file} {patch} --verbose --binary

Note that by using --binary patch.exe will no longer affected by line ending characters issue

sina.salek.ws
Feel freedom with open source softwares

Patch files sometime patch multiple files

glass.dimly - June 18, 2008 - 19:38

If you get a "Patch can't find the target file", but the first hunk seems to have worked, then your patch file might require a second file. The patch will give you a little prompt like "file to patch>".

Look at the output just above the prompt and enter the location of the file that caused patch to choke.

 
 

Drupal is a registered trademark of Dries Buytaert.