git-submodule.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. # if --with-git-submodules=ignore, do nothing
  10. test "$command" = "ignore" && exit 0
  11. test -z "$GIT" && GIT=git
  12. cd "$(dirname "$0")/.."
  13. update_error() {
  14. echo "$0: $*"
  15. echo
  16. echo "Unable to automatically checkout GIT submodules '$modules'."
  17. echo "If you require use of an alternative GIT binary (for example to"
  18. echo "enable use of a transparent proxy), then please specify it by"
  19. echo "running configure by with the '--with-git' argument. e.g."
  20. echo
  21. echo " $ ./configure --with-git='tsocks git'"
  22. echo
  23. echo "Alternatively you may disable automatic GIT submodule checkout"
  24. echo "with:"
  25. echo
  26. echo " $ ./configure --with-git-submodules=validate"
  27. echo
  28. echo "and then manually update submodules prior to running make, with:"
  29. echo
  30. echo " $ scripts/git-submodule.sh update $modules"
  31. echo
  32. exit 1
  33. }
  34. validate_error() {
  35. if test "$1" = "validate"; then
  36. echo "GIT submodules checkout is out of date, and submodules"
  37. echo "configured for validate only. Please run"
  38. echo " scripts/git-submodule.sh update $maybe_modules"
  39. echo "from the source directory or call configure with"
  40. echo " --with-git-submodules=update"
  41. echo "To disable GIT submodules validation, use"
  42. echo " --with-git-submodules=ignore"
  43. fi
  44. exit 1
  45. }
  46. modules=""
  47. for m in $maybe_modules
  48. do
  49. $GIT submodule status $m 1> /dev/null 2>&1
  50. if test $? = 0
  51. then
  52. modules="$modules $m"
  53. else
  54. echo "warn: ignoring non-existent submodule $m"
  55. fi
  56. done
  57. if test -n "$maybe_modules" && ! test -e ".git"
  58. then
  59. echo "$0: unexpectedly called with submodules but no git checkout exists"
  60. exit 1
  61. fi
  62. case "$command" in
  63. status|validate)
  64. if test -z "$maybe_modules"
  65. then
  66. test -s ${substat} && validate_error "$command" || exit 0
  67. fi
  68. test -f "$substat" || validate_error "$command"
  69. for module in $modules; do
  70. CURSTATUS=$($GIT submodule status $module)
  71. OLDSTATUS=$(cat $substat | grep $module)
  72. if test "$CURSTATUS" != "$OLDSTATUS"; then
  73. validate_error "$command"
  74. fi
  75. done
  76. exit 0
  77. ;;
  78. update)
  79. if test -z "$maybe_modules"
  80. then
  81. test -e $substat || touch $substat
  82. exit 0
  83. fi
  84. $GIT submodule update --init $modules 1>/dev/null
  85. test $? -ne 0 && update_error "failed to update modules"
  86. $GIT submodule status $modules > "${substat}"
  87. test $? -ne 0 && update_error "failed to save git submodule status" >&2
  88. ;;
  89. esac
  90. exit 0