-
-
Save costdev/b9d01f4b8f1987497b75547805c326ac to your computer and use it in GitHub Desktop.
Autofix a patch with a single sniff.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Change to the root directory. | |
cd $(git rev-parse --show-toplevel) | |
# A single argument should be provided: The path to the local patch file. | |
PATCH_RESULTS=$(grunt patch:$1) | |
# Detect a patch failure and exit. | |
if [ "$PATCH_RESULTS" == '*HUNK failed*' ] || [ "$PATCH_RESULTS" == '*unexpected*' ]; then | |
echo "Patch needs manual refresh. Add the 'needs-refresh' keyword to the ticket." | |
# Delete .orig files. | |
find . -name "*.orig" -type f -delete | |
# Delete .rej files. | |
find . -name "*.rej" -type f -delete | |
# Restore the working tree. | |
git restore . | |
exit 0 | |
fi | |
# Add the standard. dealerdirect/phpcodesniffer-composer-installer automatically adds this to "installed_paths". | |
yes | composer require slevomat/coding-standard --dev | |
# Run the relevant autofix against the changed patch files. | |
vendor/bin/phpcbf $(git diff --name-only) --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.ControlStructures.DisallowYodaComparison | |
# Remove the standard before updating the patch file (clears composer.json changes from the working tree). | |
yes | composer remove slevomat/coding-standard --dev | |
# Update the patch file. | |
git diff > $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment