]>
Commit | Line | Data |
---|---|---|
2560d699 LO |
1 | #!/bin/bash -e |
2 | # | |
3 | # This script is intended as a helper when rebasing from its master branch. | |
4 | # | |
5 | ||
6 | LOCAL_BRANCH= | |
7 | RELEASE_REPO= | |
8 | SOURCE_RELEASE_BRANCH= | |
7651bc80 | 9 | OWN= |
2560d699 LO |
10 | |
11 | function out() | |
12 | { | |
13 | local rc="${?}" | |
14 | trap - EXIT INT TERM HUP | |
15 | [ "${rc}" -eq 0 ] || echo "Error: Script failed" | |
16 | exit "${rc}" | |
17 | } | |
18 | ||
19 | trap out EXIT INT TERM HUP | |
20 | ||
21 | if [ -f debian/debian.env ]; then | |
22 | # shellcheck disable=SC1091 | |
23 | . debian/debian.env | |
24 | fi | |
25 | ||
26 | if [ ! -d "${DEBIAN}" ]; then | |
27 | echo You must run this script from the top directory of this repository. | |
28 | exit 1 | |
29 | fi | |
30 | ||
31 | CONF="${DEBIAN}"/etc/update.conf | |
32 | if [ -f "${CONF}" ]; then | |
33 | # shellcheck disable=SC1090 | |
34 | . "${CONF}" | |
35 | fi | |
36 | ||
37 | usage="$0 [-r RELEASE_REPO] [ -b REMOTE_BRANCH ] [-l LOCAL_BRANCH] [-d]"$'\n\n' | |
38 | usage+="-r RELEASE_REPO Git repository to fetch the reference branch from."$'\n' | |
39 | usage+="-b REMOTE_BRANCH Remote branch to fetch from."$'\n' | |
40 | usage+="-l LOCAL_BRANCH Use LOCAL_BRANCH as the reference branch."$'\n' | |
7651bc80 | 41 | usage+="-o Rebase against own kernel."$'\n' |
2560d699 LO |
42 | usage+="-d Dry run (do not rebase)." |
43 | ||
44 | # | |
45 | # command line options: | |
46 | # [-r RELEASE_REPO] - override default git repository. | |
47 | # [-b REMOTE_BRANCH] - override default remote branch. | |
48 | # [-l LOCAL_BRANCH] - do not fetch from remote repo, use a local branch. | |
49 | ||
7651bc80 | 50 | while getopts "r:b:l:od" opt; do |
2560d699 LO |
51 | case $opt in |
52 | r ) RELEASE_REPO="$OPTARG" ;; | |
53 | b ) SOURCE_RELEASE_BRANCH="$OPTARG" ;; | |
54 | l ) LOCAL_BRANCH="$OPTARG" ;; | |
55 | d ) DRY_RUN=1 ;; | |
7651bc80 | 56 | o ) OWN=1 ;; |
2560d699 LO |
57 | \? ) echo "usage: ${usage}"; exit ;; |
58 | esac | |
59 | done | |
60 | shift $((OPTIND - 1)) | |
61 | ||
62 | # For normal trees the fact that the update.conf file exists means that they are rebase | |
63 | # kernels. There are some special trees which started with uc20-efi, which have that | |
64 | # file because they logically depend on another source but do not have the directory | |
65 | # which DEBIAN_MASTER points to. | |
66 | IS_REBASE_KERNEL=true | |
67 | if [ ! -f "$DEBIAN/etc/update.conf" ]; then | |
68 | IS_REBASE_KERNEL=false | |
69 | elif [ "$DEBIAN_MASTER" != "" -a ! -d "$DEBIAN_MASTER" ]; then | |
70 | IS_REBASE_KERNEL=false | |
71 | fi | |
7651bc80 | 72 | if ! $IS_REBASE_KERNEL && [ -z "$OWN" ]; then |
2560d699 LO |
73 | echo "This is not a rebase kernel, no rebase should be needed, please report if otherwise" |
74 | exit 0 | |
75 | fi | |
76 | ||
7651bc80 RN |
77 | if [ "${OWN}" ] ; then |
78 | DEBIAN_MASTER="${DEBIAN}" | |
79 | fi | |
80 | ||
2560d699 LO |
81 | if [ "$DEBIAN_MASTER" = "" ]; then |
82 | echo "DEBIAN_MASTER should be defined either in ${DEBIAN}/etc/update.conf or the environment" | |
83 | exit 1 | |
84 | fi | |
85 | ||
86 | if [ -z "${LOCAL_BRANCH}" ]; then | |
87 | if [ -z "${RELEASE_REPO}" ] || [ -z "${SOURCE_RELEASE_BRANCH}" ]; then | |
88 | echo Missing update.conf or missing parameters for remote repo and branch. | |
89 | exit 1 | |
90 | fi | |
91 | # | |
92 | # Fetch the upstream branch. | |
93 | # | |
94 | git fetch "${RELEASE_REPO}" | |
95 | git fetch "${RELEASE_REPO}" "${SOURCE_RELEASE_BRANCH}" | |
96 | LOCAL_BRANCH=FETCH_HEAD | |
97 | fi | |
98 | ||
99 | # | |
100 | # Find the most recent tag on given upstream branch, then | |
101 | # rebase against it. This avoids the case where there have been some | |
102 | # commits since the last official tag. | |
103 | # | |
104 | MASTER_COMMIT=$(git log --pretty=one "${LOCAL_BRANCH}" "${DEBIAN_MASTER}" | \ | |
105 | awk ' | |
106 | /Ubuntu-/ { | |
107 | if (match($0, /UBUNTU: Ubuntu-/)) { | |
108 | print $1 | |
109 | exit | |
110 | } | |
111 | } | |
112 | ' | |
113 | ) | |
114 | # | |
115 | # Find the current merge point where current branch was based. | |
116 | # | |
117 | BASE_COMMIT=$(git log --pretty=one "${DEBIAN_MASTER}" | \ | |
118 | awk ' | |
119 | /Ubuntu-/ { | |
120 | if (match($0, /UBUNTU: Ubuntu-/)) { | |
121 | print $1 | |
122 | exit | |
123 | } | |
124 | } | |
125 | ' | |
126 | ) | |
127 | if [ "${MASTER_COMMIT}" = "${BASE_COMMIT}" ]; then | |
128 | echo Already up to date. | |
129 | exit 0 | |
130 | fi | |
131 | ||
132 | if [ -z "${MASTER_COMMIT}" ] || [ -z "${BASE_COMMIT}" ]; then | |
133 | echo "Could not find either master or base commit." | |
134 | echo "master commit: ${MASTER_COMMIT}" | |
135 | echo "base commit: ${BASE_COMMIT}" | |
136 | exit 1 | |
137 | fi | |
138 | ||
139 | MASTER_VERSION=$(git show --format=%s -s "$MASTER_COMMIT" | sed 's/^UBUNTU: //') | |
140 | BASE_VERSION=$(git show --format=%s -s "$BASE_COMMIT" | sed 's/^UBUNTU: //') | |
141 | echo "Rebase still needed between $BASE_VERSION and $MASTER_VERSION." | |
142 | ||
143 | if [ "${DRY_RUN}" ]; then | |
144 | echo "DRY RUN: git rebase --onto ${MASTER_COMMIT} ${BASE_COMMIT}" | |
145 | exit 0 | |
146 | fi | |
147 | ||
148 | git rebase --onto "${MASTER_COMMIT}" "${BASE_COMMIT}" |