[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-patch] zero exit status when all hunks are applied
From: |
Tom Hale |
Subject: |
[bug-patch] zero exit status when all hunks are applied |
Date: |
Thu, 25 Aug 2016 18:09:42 +0700 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
I'm of making a pull request that allows patch to exit(0) when all
rejected hunks are already applied.
This will allow idempotent patching, ie, patch to return 0 when a patch
has already been applied.
I propose an option:
-z Zero exit status when all rejected hunks are already applied
Currently, code like this is required, which doesn't exactly make for
ease of use when ensuring robustness:
# If we could reverse the patch, then it has already been applied; skip it
if patch --dry-run --reverse -d "$gem_dir" -fp1 --ignore-whitespace \
-i "$patch" >/dev/null 2>&1; then
echo "skipping (already applied)"
continue
else # patch not yet applied
echo "patching..."
# Patch returns non-zero if some hunks have already been applied
if ! patch -d "$gem_dir" -fsp1 --ignore-whitespace -i "$patch"; then
# Check that the patch was fully applied by pretending to reverse it
if patch --dry-run --reverse -d "$gem_dir" -fp1 --ignore-whitespace \
-i "$patch" >/dev/null 2>&1; then
echo "Ignoring failure: hunk(s) were already applied"
else
echo "Patch failed for $gem_dir" >&2; exit 1;
fi
fi
fi
Would you consider including such a pull request?
Regards,
Tom Hale
- [bug-patch] zero exit status when all hunks are applied,
Tom Hale <=