1

Can patch be invoked with idempotency; i.e., is there some combination of options that will cause repeated invocations of patch to have the same effect as a single invocation of patch (for a non-empty diff)?

2
  • 1
    <mode trolling> Yep! --dry-run </mode trolling> – MC68020 Aug 10 '20 at 21:21
  • Upvoted because I love pedantry. :D Too true, if we extend the idempotency requirement to cover the exit status, this might be the only way of invoking patch on a non-empty input! Thank you, @MC68020, for reminding me that a null effect is always idempotent. – rubicks Aug 11 '20 at 15:21
2

Some patches can be applied multiple times, so this can’t be guaranteed; but

patch -N -r- -i your.patch

will apply your.patch, ignoring any hunks which have already been applied.

-N avoids trying to revert an already-applied patch, and -r- skips saving failed hunks to .rej files.

2
  • Is there anything that allows patch to return success in the course of skipping already-applied hunks? – rubicks Aug 10 '20 at 21:38
  • No, it only ever returns success if all hunks are applied successfully. Depending on your scenario, the distinction between exit code 1 (at least one hunk failed) and 2 (more serious trouble) might be useful. – Stephen Kitt Aug 10 '20 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.