Created
October 10, 2015 04:03
-
-
Save aikar/01ebac4bef2a06934208 to your computer and use it in GitHub Desktop.
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 | |
applied=$(echo $1 | sed 's/.patch$/-applied\.patch/g') | |
if [ "$1" == "--reset" ]; then | |
git am --abort | |
git reset --hard | |
git clean -f | |
exit 0 | |
fi | |
if [ ! -f "$1" ]; then | |
echo "No patch found $1"; | |
exit 1; | |
fi | |
git am -3 $1 || ( | |
echo "Failures - Wiggling" | |
git reset --hard | |
git clean -f | |
errors=$(git apply --rej $1 2>&1) | |
echo "$errors" >> ~/patch.log | |
export missingfiles="" | |
export summaryfail="" | |
export summarygood="" | |
for i in $(find . -name \*.rej); do | |
base=$(echo "$i" | sed 's/.rej//g') | |
if [ -f "$i" ]; then | |
sed -e 's/^diff a\/\(.*\) b\/\(.*\)[[:space:]].*rejected.*$/--- \1\n+++ \2/' -i $i && wiggle -v --replace "$base" "$i" | |
rm "$base.porig" "$i" | |
else | |
echo "No such file: $base" | |
missingfiles="$missingfiles\n$base" | |
fi | |
done | |
for i in $(git status --porcelain | awk '{print $2}'); do | |
filedata=$(cat "$i") | |
if [ -f "$1" ] && [[ "$filedata" == *"<<<<<"* ]]; then | |
export summaryfail="$summaryfail\nFAILED TO APPLY: $i" | |
else | |
git add "$i" | |
export summarygood="$summarygood\nAPPLIED CLEAN: $i" | |
fi | |
done | |
echo -e "$summarygood" | |
echo -e "$summaryfail" | |
if [[ "$errors" == *"No such file"* ]]; then | |
echo "==========================="; | |
echo " " | |
echo " MISSING FILES" | |
echo $(echo "$errors" | grep "No such file") | |
echo -e "$missingfiles" | |
echo " " | |
echo "==========================="; | |
fi | |
git st | |
git diff | |
) | |
if [[ "$1" != *-applied.patch ]]; then | |
mv "$1" "$applied" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment