Last active
September 9, 2015 08:40
-
-
Save anavarre/dee42163f15519bbcc41 to your computer and use it in GitHub Desktop.
Prototype - Rerolling Drupal patches
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
#!/usr/bin/env bash | |
# Invoke the script from anywhere (e.g .bashrc alias) | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
source ${DIR}/common | |
source ${DIR}/functions.sh | |
PATCH=$1 | |
patch_check | |
reroll_prep | |
reroll |
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
# Colors | |
GREEN="\033[0;32m" | |
RED="\033[0;31m" | |
BLUE="\033[94m" | |
COLOR_ENDING="\033[0m" |
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
patch_check() { | |
LOG='/tmp/apply-patch.log' | |
touch ${LOG} | |
${GIT} apply --check ${PATCH} >> ${LOG} 2>&1 | |
CHECK=$(grep -o 'patch does not apply' ${LOG}) | |
rm ${LOG} | |
} | |
reroll_prep() { | |
if [[ -z ${CHECK} ]]; then | |
${GIT} apply --index -v ${PATCH} | |
exit 1 | |
else | |
echo "Patch does not apply." | |
echo -n "Patch date (e.g. 2015-01-23): " | |
read DATE_ISO | |
echo -n "Drupal issue #: " | |
read DRUPAL_ISSUE | |
echo -n "Comment #: " | |
read COMMENT_ID | |
fi | |
} | |
reroll() { | |
COMMIT_ID=$(git log --before=${DATE_ISO} | head -n1 | awk {'print $2'}) | |
git checkout -q ${COMMIT_ID} | |
git checkout -b ${DRUPAL_ISSUE}-${COMMENT_ID} | |
${GIT} apply --index ${PATCH} | |
${GIT} commit -qm "${DRUPAL_ISSUE}-${COMMENT_ID}" | |
echo -e "${BLUE}Rerolling...${COLOR_ENDING}" | |
git rebase ${HEAD} | |
# Todo: add check for successful rebase or merge conflict(s). | |
echo -e "${BLUE}Creating patch...${COLOR_ENDING}" | |
git diff ${HEAD} ${DRUPAL_ISSUE}-${COMMENT_ID} > ${DRUPAL_ISSUE}-${COMMENT_ID}.patch | |
echo -e "${BLUE}Upload ${DRUPAL_ISSUE}-${COMMENT_ID}.patch to https://www.drupal.org/node/${DRUPAL_ISSUE}...${COLOR_ENDING}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment