I have patch file describing changes to multiple files to apply to the contents of a directory.
I would like to apply it only if all files can be patched successfully. If any one file cannot be patched, I would like to abort the process without modifying anything.
I could do a dry run first, parse the output and see if any hunk fails before applying it for real, but there must be a better way to do this.
Edit~ What I have is a series of folders with html/css, one for each of our users that they can modify. Unmodified folders are symlinks.
Changes made are usually very small, so when we release an update for the default code there should be no problem with applying a patch to update them most of the time.
I’d recommend doing a dry run. You don’t need to parse the output, just redirect it to /dev/null. The exit code tells you if it worked or not.
From the man page for
patch, under “Diagnostics”: