Applying a patch file in a powershell script

Viewed 943

I am trying to automate building some dependencies on my Win machine, throught Powershell scripting. I am just fetching sources from Github, building throught CMake etc. For one of the dependencies, I need to apply a patch from a pull request.

In my script, I am creating the asm.patch file automatically. This is the correct patch file. If I apply this patch on a Unix environment through patch < asm.patch, everything works fine. I have no way of applying this patch file on my Powershell script though.

The thing I tried, I installed GnuWin32 native port of patch. In my script, I am calling it like patch -i asm.patch because Powershell does not let me to use token <. It calls the patch command correctly. But GnuWin32 patch port opens up a dialog related to permissions. So it is not useful for my automation needs.

Question is, what is the standard way of applying .patch file on Powershell scripts?

2 Answers

git apply worked eventually

I was working with a temporary, generated project in a git 'ignored' folder. The patch was oriented to the folder of the temporary project but because of the surrounding git project all I got was Skipped patch.

Using git init <TEMP_PROJECT_FOLDER> allowed the patch to be applied although this may not be necessary for you.

Other tips:

  • --directory resulted in error: invalid path because PowerShell's tolerance of / in paths is only superficial (I gather). So need to change current working directory.
  • --verbose helps but isn't comprehensive
  • Other options from @Moerwald: --ignore-space-change --ignore-whitespace --whitespace=nowarn

Is git apply an alternative? If so, try:

  invoke-expression "git apply --ignore-space-change --ignore-whitespace --whitespace=no warn file.patch
Related