You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updateSubModules.sh 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. GIT=`which git`
  3. # Init any new submodules
  4. ${GIT} submodule init
  5. DIR=${PWD}
  6. # Check every submodule.
  7. ${GIT} submodule status | while read -r LINE; do
  8. MISSING=`echo ${LINE} | grep ^-`
  9. CHANGED=`echo ${LINE} | grep ^+`
  10. MODULE=`echo ${LINE} | awk '{print $2}'`
  11. # If the module hasn't been checked out yet, then checkout.
  12. if [ "${MISSING}" != "" ]; then
  13. ${GIT} submodule update -- ${MODULE}
  14. if [ ${?} -ne 0 ]; then
  15. echo "Error: Unable to update submodule ${MODULE}, aborting."
  16. exit 1;
  17. fi;
  18. # Else, rebase current changes onto the new upstream version.
  19. # - If nothing has changed, this will just be a fast forward like normal
  20. # - If there are uncommited changes, this will fail and leave the submodule
  21. # as it is at the moment.
  22. # - If there are commited revisions on top of the submodule, then they will
  23. # be rebased onto the revision used upstream,
  24. elif [ "${CHANGED}" != "" ]; then
  25. # Try using git to do this. (1.6.4+)
  26. ${GIT} submodule update --rebase -- ${MODULE}
  27. # Check to see if the above command worked, if not then do it
  28. # manually.
  29. if [ "${?}" -ne 0 ]; then
  30. # Get the revision used upstream
  31. OLDREV=`git diff ${MODULE} | grep -- "-Subproject" | awk '{print $3}'`
  32. if [ "${OLDREV}" != "" ]; then
  33. cd ${MODULE}
  34. ${GIT} fetch origin
  35. ${GIT} rebase ${OLDREV}
  36. if [ ${?} -ne 0 ]; then
  37. echo "Error: Rebase failed on ${MODULE}, continuing with current HEAD."
  38. ${GIT} rebase --abort
  39. fi;
  40. fi;
  41. fi;
  42. fi;
  43. # Go back to main project directory.
  44. cd ${DIR}
  45. done;