"All or none" policy for patch
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 t开发者_开发问答o 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":
patch's exit status is 0 if all hunks are applied successfully, 1 if some hunks cannot be applied, and 2 if there is more serious trouble. When applying a set of patches in a loop it behooves you to check this exit status so you don't apply a later patch to a partially patched file.
Use revision control.
That way, you can revert if the patch was not fully applied.
精彩评论