git: split applypatch into a script and make it actually work