tryapplydiff.sh 798 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. # Hacky script to sort patches based on whether they apply cleanly or not
  3. p=1 # patch -p
  4. okdir="./patches-ok" # OK directory
  5. faildir="./patches-fail" # Fail directory
  6. alreadydir="./patches-already" # Already applied directory
  7. tmpfile="$(mktemp)"
  8. mkdir -p "$okdir"
  9. mkdir -p "$faildir"
  10. mkdir -p "$alreadydir"
  11. while [ $# -ne 0 ]; do
  12. diff="$1"
  13. shift
  14. [ -f "$diff" ] || continue
  15. echo "Checking $diff..."
  16. patch --dry-run -p$p < "$diff" 2>&1 >$tmpfile
  17. res=$?
  18. cat $tmpfile
  19. echo "RES == $res"
  20. if [ "x$(grep 'Reversed (or previously applied)' "$tmpfile")" != "x" ]; then
  21. cp "$diff" "$alreadydir/$(basename "$diff")"
  22. else
  23. if [ $res -eq 0 ]; then
  24. cp "$diff" "$okdir/$(basename "$diff")"
  25. else
  26. cp "$diff" "$faildir/$(basename "$diff")"
  27. fi
  28. fi
  29. echo
  30. done
  31. rm $tmpfile