blob: 536b3318573d8b5595450174c990fd9b1c420715 [file] [log] [blame]
Raymond Maoc5d2ec82024-07-25 06:57:51 -07001#!/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
15set -e
16
17print_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
24if [ $# -ne 3 ]; then
25 print_usage
26 exit 1
27fi
28
29op=$1
30subtree_name=$2
31ref=$3
32
33set_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
57set_params
58
59merge_commit_msg=$(cat << EOF
60Subtree merge tag '$ref' of $subtree_name repo [1] into $path
61
62[1] $repo_url
63EOF
64)
65
66remote_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
76if [ "$op" = "pull" ]; then
77 remote_add_and_fetch
78 git subtree pull --prefix $path $remote_name "$ref" --squash -m "$merge_commit_msg"
79elif [ "$op" = "pick" ]; then
80 remote_add_and_fetch
81 git cherry-pick -x --strategy=subtree -Xsubtree=$path/ "$ref"
82else
83 print_usage
84 exit 1
85fi