pull_submodule.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2020 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Internal script for pull_submodules.sh. Not intended to be used directly.
  18. set -e
  19. CHIP_ROOT="$(dirname "$0")/../.."
  20. if [[ -z "$name" || -z "$toplevel" ]]; then
  21. echo >&2 "This script should be run via update_submodules.sh"
  22. exit 1
  23. fi
  24. get_submodule_config() {
  25. git config --file "$toplevel/.gitmodules" "submodule.$name.$1"
  26. }
  27. SUBMODULE_URL=$(get_submodule_config url)
  28. SUBMODULE_BRANCH=$(get_submodule_config branch)
  29. SUBMODULE_PATH=$(get_submodule_config path)
  30. git fetch --quiet "$SUBMODULE_URL" "$SUBMODULE_BRANCH"
  31. HEAD_COMMIT=$(git -C "$toplevel" rev-parse HEAD:"$SUBMODULE_PATH")
  32. FETCH_COMMIT="$(git rev-parse FETCH_HEAD)"
  33. if [[ "$HEAD_COMMIT" == "$FETCH_COMMIT" ]]; then
  34. exit 0
  35. fi
  36. git checkout --quiet "$FETCH_COMMIT"
  37. git -C "$toplevel" add "$SUBMODULE_PATH"
  38. echo " git -C $SUBMODULE_PATH log $(git rev-parse --short "$HEAD_COMMIT")..$(git rev-parse --short "$FETCH_COMMIT")"