update-subtree.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. set -e
  3. if [ "$(git rev-parse --show-prefix)" != "" ]; then
  4. echo "Must be in root of git repo!"
  5. exit
  6. fi
  7. if [ "${1}" = "" ]; then
  8. echo "Usage: <path>"
  9. exit
  10. fi
  11. path="${1}"
  12. while read repo branch subdir; do
  13. if [ "${repo:0:1}" = "#" ]; then
  14. continue
  15. fi
  16. exec 69>&1
  17. if [ "${subdir}" = "/" ]; then
  18. result="$(git subtree pull -P "${path}" "${repo}" "${branch}" -m "Merge ${path} from ${repo}" 2>&1 | tee /proc/self/fd/69)"
  19. else
  20. result="$(bash .utils/subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" merge 2>&1 | tee /proc/self/fd/69)"
  21. fi
  22. if grep "Automatic merge failed; fix conflicts and then commit the result." <<< "$result" > /dev/null; then
  23. echo "MERGE_MSG: Merge ${path} from ${repo}"
  24. notify-send -a Git -i git "Subtree merge failed" "Resolve current index to continue" &> /dev/null | true
  25. while true; do
  26. echo "Resolve current index then press Enter..."
  27. read
  28. if git diff --quiet && git diff --cached --quiet && git merge HEAD &> /dev/null; then
  29. break
  30. fi
  31. sleep 1
  32. done
  33. fi
  34. done < "${path}/.gitsubtree"