patch file error

Gentry A White December 5, 2011

I am using Source Tree on Snow Leopard and my collaborator is using TortoiseHg on a Windows machine. They sent me a patch file they created. When I try to apply the patch through Source Tree I get the following error:

patch -f -p0 --input=/Users/bobsmith/Examples/Test.repos/2.patch

can't find file to patch at input line 11

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

--------------------------

|# HG changeset patch

|# User Bob Dobbsr <bob.dobbss@generic.com>

|# Date 1323115006 18000

|# Node ID 542abe6c0a14a38eb7da674768d7eba26de52f58

|# Parent 9a0d93cd89a62635aa5272a917910529b3d30b64

|Made two changes and added a conclusion section.

|

|diff -r 9a0d93cd89a6 -r 542abe6c0a14 Example.tex

|--- a/Example.texFri Dec 02 12:12:43 2011 +1000

|+++ b/Example.texMon Dec 05 14:56:46 2011 -0500

--------------------------

No file to patch. Skipping patch.

2 out of 2 hunks ignored

Completed with errors, see above

I previously ran the patch file through dos2unix to see if that helps.

I can get the file to work with the CLI command:

patch Example.tex 2patch.diff

Any ideas on why the GUI version through Source Tree isn't working?

4 answers

1 accepted

0 votes
Answer accepted
Gentry A White December 21, 2011

My assosiciate is still haveing problems with the windows version of Tortoise Hg, but I think that the issue was the wrong strip value, the other issues are probably not a Source Tree issue.

0 votes
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2011

The 'Apply Patch' UI in SourceTree includes the 'strip' option. SourceTree tries to figure this out automatically - I wrote a bunch of parsing routines and regexes to detect the strip options and base path so you wouldn't have to figure this out on your own like you do on the command line. The Apply Patch window should say in the text area in the middle whether it has figured out the base path & strip options correctly - it also tells you whether it's detected a plain GNU patch or a patch with full commit info.

I've got a bunch of tests for this and it's picked up the strip options correctly when I've tried it.

So when you pick this patch, what does the text area say about detecting the strip option? It should tell you if it can't figure it out. If that's the case you can specify it yourself, but I'm curious why it couldn't do it - I've fed it quite a lot of variations so if there's one it can't understand I'd like to have an example.

Gentry A White December 5, 2011

Steve -- thanks for the reply. I download the patch to the repository from an e-mail and then use the 'Apply Patch' UI. I get the message "Patch contains a Mercurial changeset. Could not determine strip/base path options from patch file entry: a/Example.tex" If I then use the toggle on the UI to set the Strip to 1 and click 'OK' the file works fine.

My collaborator noted that the patch I sent them in TortoiseHg on a Windows machine gives a "Bad Hunk" error, but if they cut and paste the file contents to the clipboard it works fine. I believe that migth be a end of line character issue, but it seems to be a work araound.

I'd say my problem is solved, but I can give you some more precise code if you like, I can send you the repository as well, it is a small toy example we are playing with to learn the system.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2011

Yes, this may have just been a line ending issue - this is common when you try to use GNU patch or other tools across platforms. Glad you got it sorted out!

0 votes
Barry Weinstein December 5, 2011

From what I see above you'll always want to strip the "a/" and the "b/". So it seems the strip num should be 1.

0 votes
Gentry A White December 5, 2011

FYI, since I am trying to apply a patch in the same directory should I set the strip num to 1 instead of 0? That seemed to work, but I am not sure.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events