]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - debian/scripts/helpers/rebase
UBUNTU: [Packaging] update helper scripts
[mirror_ubuntu-kernels.git] / debian / scripts / helpers / rebase
CommitLineData
2560d699
LO
1#!/bin/bash -e
2#
3# This script is intended as a helper when rebasing from its master branch.
4#
5
6LOCAL_BRANCH=
7RELEASE_REPO=
8SOURCE_RELEASE_BRANCH=
7651bc80 9OWN=
2560d699
LO
10
11function out()
12{
13 local rc="${?}"
14 trap - EXIT INT TERM HUP
15 [ "${rc}" -eq 0 ] || echo "Error: Script failed"
16 exit "${rc}"
17}
18
19trap out EXIT INT TERM HUP
20
21if [ -f debian/debian.env ]; then
22 # shellcheck disable=SC1091
23 . debian/debian.env
24fi
25
26if [ ! -d "${DEBIAN}" ]; then
27 echo You must run this script from the top directory of this repository.
28 exit 1
29fi
30
31CONF="${DEBIAN}"/etc/update.conf
32if [ -f "${CONF}" ]; then
33 # shellcheck disable=SC1090
34 . "${CONF}"
35fi
36
37usage="$0 [-r RELEASE_REPO] [ -b REMOTE_BRANCH ] [-l LOCAL_BRANCH] [-d]"$'\n\n'
38usage+="-r RELEASE_REPO Git repository to fetch the reference branch from."$'\n'
39usage+="-b REMOTE_BRANCH Remote branch to fetch from."$'\n'
40usage+="-l LOCAL_BRANCH Use LOCAL_BRANCH as the reference branch."$'\n'
7651bc80 41usage+="-o Rebase against own kernel."$'\n'
2560d699
LO
42usage+="-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 50while 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
59done
60shift $((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.
66IS_REBASE_KERNEL=true
67if [ ! -f "$DEBIAN/etc/update.conf" ]; then
68 IS_REBASE_KERNEL=false
69elif [ "$DEBIAN_MASTER" != "" -a ! -d "$DEBIAN_MASTER" ]; then
70 IS_REBASE_KERNEL=false
71fi
7651bc80 72if ! $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
75fi
76
7651bc80
RN
77if [ "${OWN}" ] ; then
78 DEBIAN_MASTER="${DEBIAN}"
79fi
80
2560d699
LO
81if [ "$DEBIAN_MASTER" = "" ]; then
82 echo "DEBIAN_MASTER should be defined either in ${DEBIAN}/etc/update.conf or the environment"
83 exit 1
84fi
85
86if [ -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
97fi
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#
104MASTER_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#
117BASE_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)
127if [ "${MASTER_COMMIT}" = "${BASE_COMMIT}" ]; then
128 echo Already up to date.
129 exit 0
130fi
131
132if [ -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
137fi
138
139MASTER_VERSION=$(git show --format=%s -s "$MASTER_COMMIT" | sed 's/^UBUNTU: //')
140BASE_VERSION=$(git show --format=%s -s "$BASE_COMMIT" | sed 's/^UBUNTU: //')
141echo "Rebase still needed between $BASE_VERSION and $MASTER_VERSION."
142
143if [ "${DRY_RUN}" ]; then
144 echo "DRY RUN: git rebase --onto ${MASTER_COMMIT} ${BASE_COMMIT}"
145 exit 0
146fi
147
148git rebase --onto "${MASTER_COMMIT}" "${BASE_COMMIT}"