Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

updateSubModules.sh 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. # Get the revision used upstream
  26. OLDREV=`git diff ${MODULE} | grep -- "-Subproject" | awk '{print $3}'`
  27. if [ "${OLDREV}" != "" ]; then
  28. cd ${MODULE}
  29. ${GIT} fetch origin
  30. ${GIT} rebase ${OLDREV}
  31. if [ ${?} -ne 0 ]; then
  32. echo "Error: Rebase failed on ${MODULE}, continuing with current HEAD."
  33. ${GIT} rebase --abort
  34. fi;
  35. fi;
  36. fi;
  37. # Go back to main project directory.
  38. cd ${DIR}
  39. done;