3

I'm trying to apply patch generated from some git repository. Patch context line looks like this

else if ( o is Item )

and in my code it looks like this

else if (o is Item)

When I apply patch

$ git apply -v --check --directory=myroot --ignore-space-change --ignore-whitespace ../patches/0003-some-name.patch

it says that

error: while searching for:

and provides the context block which has differences only in spaces mentioned above. When I fix the issue with the spaces the problem goes away. Is there a way to specify that spaces inside of context line can be ignored?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Soteric
  • 3,070
  • 5
  • 24
  • 23
  • Not sure how `git apply` works, but I would have thought that ignoring whitespace wouldn't work with your example. If you assume it uses some kind of "tokenisation" when ignoring whitespace, then the first line has 7 "tokens", and the second has 5. You would need it to somehow parse the language you're using to recognise that the two lines are syntactically the same. – icabod Jan 13 '14 at 10:18
  • I came to conclusion that it's impossible with git. As you said then it won't make difference between, for example, "elseif" and "else if" which may have completely different meaning and break functionality after merge. – Soteric Jan 14 '14 at 09:35

1 Answers1

0

As long as we're just talking about whitespace: git apply has the --ignore-whitespace option:

When applying a patch, ignore changes in whitespace in context lines if necessary

This should help you. Reads like someone had the same issues like you before :-)

If it's not just a whitespace problem in context lines, I usually use git apply with the --reject option: hunks that could be applied will be applied, those with problems are stored in a .rej file parallel to the patched file.

eckes
  • 64,417
  • 29
  • 168
  • 201
  • 1
    Thanks but --ignore-whitespace doesn't help. With --reject option I have to resolve all the patches manually. Probably it worths to bring my and that repository code to common style but first I'd like to find out if git can handle it for me. – Soteric Jan 13 '14 at 10:02
  • Finally I came to conclusion that it's impossible with git. I use "git apply" with --reject option as was mentioned in this answer. – Soteric Jan 14 '14 at 09:36