Apply patches or change sets from core.trac.wordpress.org tickets.
#!/usr/bin/env bash | |
# ==================================================================================== | |
# Script to install patches or changesets to https://core.trac.wordpress.org | |
# I use with Local Lightning by Flywheel by installing in `/app` directory. | |
# | |
# Patches and changesets are saved in `/tmp/` as a default. | |
# You will use the patch URL in the script. | |
# ==================================================================================== | |
# ==================================================================================== | |
# Instructions | |
# | |
# 1 - Right click your site in the Local Lightning App and click Open Site Shell. | |
# | |
# 2 - Download this file (apply-trac-patch.sh) inside your site's /app folder | |
# curl -o apply-trac-patch.sh https://gist.githubusercontent.com/afragen/977d765414189d5f5fae42215fe92a27/raw/apply-trac-patch.sh | |
# | |
# 3 - Run the script from the /app/public folder | |
# bash ../apply-trac-patch.sh | |
# | |
# If your installation is based upon develop.git.wordpress.org | |
# at this time it is recommended to use the 'npm run grunt patch:####' | |
# https://make.wordpress.org/core/handbook/testing/patch/#using-grunt | |
# | |
# ticket - is the filename of a patch attached to a Trac ticket. | |
# | |
# changeset - is a committed changeset number | |
# ==================================================================================== | |
echo "Assumes a WordPress installation based on core.git.wordpress.org" | |
echo "If WordPress installation based on develop.git.wordpress.org" | |
echo " use 'npm run grunt patch:#####'" | |
echo | |
PATCH_TYPE="ticket" | |
printf "Does the patch come from a Trac ticket or a Changeset (TICKET|changeset)? " | |
read -e input | |
input=$(echo "$input" | tr '[:upper:]' '[:lower:]') | |
#input="${input%/}" # Strip trailing slash | |
PATCH_TYPE="${input:-$PATCH_TYPE}" | |
DEFAULT_SAVED_DIR="/tmp" | |
mkdir -p "$DEFAULT_SAVED_DIR/" | |
echo "Where do we save the patch?" | |
printf "($DEFAULT_SAVED_DIR): " | |
read -e input | |
input="${input%/}" # Strip trailing slash | |
DEFAULT_SAVED_DIR="${input:-$DEFAULT_SAVED_DIR}" # Populate with default if empty | |
if [[ $PATCH_TYPE == 'ticket' ]]; then | |
PATCH_DEPTH="1" | |
printf "Trac patch URL: " | |
read -e PATCH_URL | |
PATCH_URL=$(echo "$PATCH_URL" | tr -d '[[:space:]]') | |
TRAC_TICKET=$(echo "$PATCH_URL" | awk -F "/" '{print $6}') | |
PATCH=$(echo "$PATCH_URL" | awk -F "/" '{print $7}') | |
DEFAULT_PATCH_PATH="$DEFAULT_SAVED_DIR/patch_$PATCH" | |
echo "Download and modify patch from Trac ticket: $TRAC_TICKET" | |
URL="https://core.trac.wordpress.org/raw-attachment/ticket/$TRAC_TICKET/$PATCH" | |
fi | |
if [[ $PATCH_TYPE == 'changeset' ]]; then | |
PATCH_DEPTH="3" | |
printf "Changeset number from trunk: " | |
read -e CHANGESET | |
DEFAULT_PATCH_PATH="$DEFAULT_SAVED_DIR/changeset_$CHANGESET.diff" | |
echo "Download and modify patch from changeset: $CHANGESET" | |
URL="https://core.trac.wordpress.org/changeset/$CHANGESET?format=diff&new=$CHANGESET" | |
fi | |
echo | |
echo "Downloading: $URL" | |
echo | |
curl "$URL" | sed 's/Index: \(.*\)*$/git --diff \1/' | sed -e 's#/src##g' >"$DEFAULT_PATCH_PATH" | |
echo | |
echo "Patch filepath: $DEFAULT_PATCH_PATH" | |
echo | |
printf "Apply patch? (Y|n)? " | |
read -e input | |
PROCEED="${input:-y}" | |
# Allow user cancellation. | |
if [ $(echo "$PROCEED" | tr '[:upper:]' '[:lower:]') != "y" ]; then | |
echo "Aborting..." | |
exit 1 | |
fi | |
#echo "Patch depth: -p$PATCH_DEPTH" | |
patch --verbose "-p$PATCH_DEPTH" <"$DEFAULT_PATCH_PATH" | |
echo |
This comment has been minimized.
This comment has been minimized.
Modify patch to apply regardless of whether it originates from a core.git.wp.org or develop.git.wp.org installation. This removes several steps in the process. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
I don’t know if this will work correctly on Windows as I’m using/creating the
/tmp/
directory as the$DEFAULT_SAVED_DIR
. Any help to ensure this works on Windows would be appreciated.