git-submodule.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. #
  3. # This code is licensed under the GPL version 2 or later. See
  4. # the COPYING file in the top-level directory.
  5. substat=".git-submodule-status"
  6. command=$1
  7. shift
  8. maybe_modules="$@"
  9. test -z "$GIT" && GIT=git
  10. error() {
  11. echo "$0: $*"
  12. echo
  13. echo "Unable to automatically checkout GIT submodules '$modules'."
  14. echo "If you require use of an alternative GIT binary (for example to"
  15. echo "enable use of a transparent proxy), then please specify it by"
  16. echo "running configure by with the '--with-git' argument. e.g."
  17. echo
  18. echo " $ ./configure --with-git='tsocks git'"
  19. echo
  20. echo "Alternatively you may disable automatic GIT submodule checkout"
  21. echo "with:"
  22. echo
  23. echo " $ ./configure --disable-git-update"
  24. echo
  25. echo "and then manually update submodules prior to running make, with:"
  26. echo
  27. echo " $ scripts/git-submodule.sh update $modules"
  28. echo
  29. exit 1
  30. }
  31. modules=""
  32. for m in $maybe_modules
  33. do
  34. $GIT submodule status $m 1> /dev/null 2>&1
  35. if test $? = 0
  36. then
  37. modules="$modules $m"
  38. else
  39. echo "warn: ignoring non-existent submodule $m"
  40. fi
  41. done
  42. if test -n "$maybe_modules" && ! test -e ".git"
  43. then
  44. echo "$0: unexpectedly called with submodules but no git checkout exists"
  45. exit 1
  46. fi
  47. case "$command" in
  48. status)
  49. if test -z "$maybe_modules"
  50. then
  51. test -s ${substat} && exit 1 || exit 0
  52. fi
  53. test -f "$substat" || exit 1
  54. CURSTATUS=$($GIT submodule status $modules)
  55. OLDSTATUS=$(cat $substat)
  56. test "$CURSTATUS" = "$OLDSTATUS"
  57. exit $?
  58. ;;
  59. update)
  60. if test -z "$maybe_modules"
  61. then
  62. test -e $substat || touch $substat
  63. exit 0
  64. fi
  65. $GIT submodule update --init $modules 1>/dev/null
  66. test $? -ne 0 && error "failed to update modules"
  67. $GIT submodule status $modules > "${substat}"
  68. test $? -ne 0 && error "failed to save git submodule status" >&2
  69. ;;
  70. esac
  71. exit 0