2

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?

meguli
  • 1,426
  • 1
  • 18
  • 35
  • Have a look at the output of the `Get-Command -Name '*update*' | Where-Object { $_.CommandType -eq 'Function' }` command. Until you have some code in the question, please ask on https://superuser.com/ – lit Jun 29 '19 at 16:16

2 Answers2

0

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
Peter L
  • 2,921
  • 1
  • 29
  • 31
-1

Is git apply an alternative? If so, try:

  invoke-expression "git apply --ignore-space-change --ignore-whitespace --whitespace=no warn file.patch
Moerwald
  • 10,448
  • 9
  • 43
  • 83
  • This didn't work for me. Resulted in `error: invalid path` when trying to use `--directory`. Avoiding `--directory` by setting current directory doesn't help; each patches get message `Skipped patch`. My IDE can apply patch just fine however. See also [similar question](https://stackoverflow.com/questions/42386491/git-apply-skips-patches) – Peter L Jun 01 '21 at 19:09