Last active
August 29, 2015 14:03
-
-
Save neclimdul/d611b5033c6d302fab7e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# Description | |
# | |
# Many patches don't apply but can easily be reapplied by using git's very | |
# powerful merge tools. This script finds the last commit that the patch | |
# applied to, makes a temporary commit and then tries to merge against the | |
# given branch. | |
# | |
# Usage: | |
# | |
# 1) Checkout the branch you want to reapply the patch to. | |
# 2) run reapply.sh https://www.drupal.org/files/issues/foobar.patch origin/8.x | |
# 3) git diff origin/8.x > new.patch | |
# | |
PATCH="$1" | |
BRANCH="$2" | |
wget $PATCH -O tmp.patch | |
# Get a branch to work in. | |
git branch -D reapply | |
git checkout -b reapply | |
git reset --hard $BRANCH | |
# Find the last commit the patch applies to. | |
while : ; do | |
git reset --hard HEAD^ | |
git apply --index tmp.patch > /dev/null | |
if [ $? -eq 0 ]; then | |
break | |
fi | |
done | |
git commit -m "Applying $PATCH" | |
tmp=$(git merge $BRANCH) | |
if [ $? -eq 0 ]; then | |
echo 'Reapply successful.' | |
else | |
echo 'Reapply failed.' | |
fi | |
rm tmp.patch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment