2
0

git-submodule.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. for module in $modules; do
  55. CURSTATUS=$($GIT submodule status $module)
  56. OLDSTATUS=$(cat $substat | grep $module)
  57. if test "$CURSTATUS" != "$OLDSTATUS"; then
  58. exit 1
  59. fi
  60. done
  61. exit 0
  62. ;;
  63. update)
  64. if test -z "$maybe_modules"
  65. then
  66. test -e $substat || touch $substat
  67. exit 0
  68. fi
  69. $GIT submodule update --init $modules 1>/dev/null
  70. test $? -ne 0 && error "failed to update modules"
  71. $GIT submodule status $modules > "${substat}"
  72. test $? -ne 0 && error "failed to save git submodule status" >&2
  73. ;;
  74. esac
  75. exit 0