Raymond Mao | c5d2ec8 | 2024-07-25 06:57:51 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0+ |
| 3 | # |
| 4 | # Copyright (c) 2024 Linaro Limited |
| 5 | # |
| 6 | # Usage: from the top level U-Boot source tree, run: |
| 7 | # $ ./tools/update-subtree.sh pull <subtree-name> <release-tag> |
| 8 | # Or: |
| 9 | # $ ./tools/update-subtree.sh pick <subtree-name> <commit-id> |
| 10 | # |
| 11 | # The script will pull changes from subtree repo into U-Boot. |
| 12 | # It will automatically create a squash/merge commit listing the commits |
| 13 | # imported. |
| 14 | |
| 15 | set -e |
| 16 | |
| 17 | print_usage() { |
| 18 | echo "usage: $0 <op> <subtree-name> <ref>" |
| 19 | echo " <op> pull or pick" |
| 20 | echo " <subtree-name> mbedtls or dts or lwip" |
| 21 | echo " <ref> release tag [pull] or commit id [pick]" |
| 22 | } |
| 23 | |
| 24 | if [ $# -ne 3 ]; then |
| 25 | print_usage |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | op=$1 |
| 30 | subtree_name=$2 |
| 31 | ref=$3 |
| 32 | |
| 33 | set_params() { |
| 34 | case "$subtree_name" in |
| 35 | mbedtls) |
| 36 | path=lib/mbedtls/external/mbedtls |
| 37 | repo_url=https://github.com/Mbed-TLS/mbedtls.git |
| 38 | remote_name="mbedtls_upstream" |
| 39 | ;; |
| 40 | dts) |
| 41 | path=dts/upstream |
| 42 | repo_url=https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git |
| 43 | remote_name="devicetree-rebasing" |
| 44 | ;; |
| 45 | lwip) |
| 46 | path=lib/lwip/lwip |
| 47 | repo_url=https://git.savannah.gnu.org/git/lwip.git |
| 48 | remote_name="lwip_upstream" |
| 49 | ;; |
| 50 | *) |
| 51 | echo "Invalid subtree name: $subtree_name" |
| 52 | print_usage |
| 53 | exit 1 |
| 54 | esac |
| 55 | } |
| 56 | |
| 57 | set_params |
| 58 | |
| 59 | merge_commit_msg=$(cat << EOF |
| 60 | Subtree merge tag '$ref' of $subtree_name repo [1] into $path |
| 61 | |
| 62 | [1] $repo_url |
| 63 | EOF |
| 64 | ) |
| 65 | |
| 66 | remote_add_and_fetch() { |
| 67 | if [ -z "$(git remote get-url $remote_name 2>/dev/null)" ]; then |
| 68 | echo "Warning: Script automatically adds new git remote via:" |
| 69 | echo " git remote add $remote_name \\" |
| 70 | echo " $repo_url" |
| 71 | git remote add $remote_name $repo_url |
| 72 | fi |
| 73 | git fetch $remote_name master |
| 74 | } |
| 75 | |
| 76 | if [ "$op" = "pull" ]; then |
| 77 | remote_add_and_fetch |
| 78 | git subtree pull --prefix $path $remote_name "$ref" --squash -m "$merge_commit_msg" |
| 79 | elif [ "$op" = "pick" ]; then |
| 80 | remote_add_and_fetch |
| 81 | git cherry-pick -x --strategy=subtree -Xsubtree=$path/ "$ref" |
| 82 | else |
| 83 | print_usage |
| 84 | exit 1 |
| 85 | fi |