Advertisement
Guest User

Untitled

a guest
May 28th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #!/bin/bash
  2. applied=$(echo $1 | sed 's/.patch$/-applied\.patch/g')
  3. if [ "$1" == "--reset" ]; then
  4. git am --abort
  5. git reset --hard
  6. git clean -f
  7. exit 0
  8. fi
  9. if [ ! -f "$1" ]; then
  10. echo "No patch found $1";
  11. exit 1;
  12. fi
  13. git am -3 $1 || (
  14. echo "Failures - Wiggling"
  15. errors=$(git apply --rej $1 2>&1)
  16. echo "$errors"
  17. export missingfiles=""
  18. export summaryfail=""
  19. export summarygood=""
  20. for i in $(find . -name \*.rej); do
  21. base=$(echo "$i" | sed 's/.rej//g')
  22. if [ -f "$i" ]; then
  23. sed -e 's/^diff a\/\(.*\) b\/\(.*\)[[:space:]].*rejected.*$/--- \1\n+++ \2/' -i $i && wiggle -v --replace "$base" "$i"
  24. rm "$base.porig" "$i"
  25. else
  26. echo "No such file: $base"
  27. missingfiles="$missingfiles\n$base"
  28. fi
  29. done
  30. for i in $(git status --porcelain | awk '{print $2}'); do
  31. filedata=$(cat "$i")
  32. if [ -f "$1" ] && [[ "$filedata" == *"<<<<<"* ]]; then
  33. export summaryfail="$summaryfail\nFAILED TO APPLY: $i"
  34. else
  35. git add "$i"
  36. export summarygood="$summarygood\nAPPLIED CLEAN: $i"
  37. fi
  38. done
  39. echo -e "$summarygood"
  40. echo -e "$summaryfail"
  41. if [[ "$errors" == *"No such file"* ]]; then
  42. echo "===========================";
  43. echo " "
  44. echo " MISSING FILES"
  45. echo $(echo "$errors" | grep "No such file")
  46. echo -e "$missingfiles"
  47. echo " "
  48. echo "===========================";
  49. fi
  50. git st
  51. git diff
  52. )
  53. if [[ "$1" != *-applied.patch ]]; then
  54. mv "$1" "$applied"
  55. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement