]>
Commit | Line | Data |
---|---|---|
c8a6fd78 FG |
1 | #!/bin/bash |
2 | ||
3 | set -e | |
4 | ||
5 | top=$(pwd) | |
6 | ||
7 | # parameters | |
8 | kernel_submodule= | |
9 | kernel_patchdir= | |
10 | new_tag= | |
11 | rebase= | |
12 | ||
13 | # generated based on new_tag | |
14 | pq_branch= | |
15 | # previously checked out in submodule | |
16 | old_ref= | |
17 | ||
18 | function cleanup_pq_branch { | |
19 | if [[ -n $pq_branch ]]; then | |
20 | echo "cleaning up PQ branch '$pq_branch'" | |
21 | cd "${top}/${kernel_submodule}" | |
22 | git checkout --quiet $old_ref | |
23 | git reset --hard | |
24 | git branch -D "$pq_branch" | |
25 | fi | |
26 | } | |
27 | ||
28 | function error_exit { | |
29 | echo "$1" | |
30 | set +e | |
31 | ||
32 | cleanup_pq_branch | |
33 | ||
34 | cd "${top}" | |
35 | ||
36 | exit 1 | |
37 | } | |
38 | ||
39 | if [[ "$#" -lt 3 || "$#" -gt 4 ]]; then | |
40 | echo "USAGE: $0 submodule patchdir tag [rebase]" | |
41 | echo "\t fetches and checks out 'tag' in 'submodule'" | |
42 | echo "\t if 'rebase' is given, imports, rebases and exports patchqueue from 'patchdir' as well" | |
43 | exit 1 | |
44 | fi | |
45 | ||
46 | kernel_submodule=$1 | |
47 | if [ ! -d "${kernel_submodule}" ]; then | |
48 | error_exit "'${kernel_submodule}' must be a directory!" | |
49 | fi | |
50 | ||
51 | kernel_patchdir=$2 | |
52 | if [ ! -d "${kernel_patchdir}" ]; then | |
53 | error_exit "'${kernel_patchdir}' must be a directory!" | |
54 | fi | |
55 | ||
56 | new_tag=$3 | |
57 | rebase=$4 | |
58 | ||
59 | if [[ -n $(git status --untracked-files=no --porcelain) ]]; then | |
60 | error_exit "working directory unclean, aborting" | |
61 | fi | |
62 | ||
63 | ||
64 | cd "${kernel_submodule}" | |
65 | ## check for tag and fetch if needed | |
66 | echo "checking for tag '${new_tag}'" | |
67 | if [[ -z $(git tag -l "${new_tag}") ]]; then | |
68 | echo "tag not found, fetching and retrying" | |
69 | git fetch --tags | |
70 | fi | |
71 | if [[ -z $(git tag -l "${new_tag}") ]]; then | |
72 | error_exit "tag not found, aborting" | |
73 | fi | |
74 | echo "tag found" | |
75 | cd "${top}" | |
76 | ||
77 | if [[ -n "$rebase" ]]; then | |
78 | echo "" | |
79 | echo "automatic patchqueue rebase enabled" | |
80 | cd "${kernel_submodule}" | |
81 | ## preparing patch queue branch | |
82 | old_ref=$(git rev-parse HEAD) | |
83 | pq_branch="auto_pq/${new_tag}" | |
84 | cd "${top}" | |
85 | ||
86 | echo "previous HEAD: ${old_ref}" | |
87 | ||
88 | echo "" | |
89 | "${top}/debian/scripts/import-patchqueue" "${kernel_submodule}" "${kernel_patchdir}" "${pq_branch}" || error_exit "failed to import patchqueue" | |
90 | ||
91 | cd "${kernel_submodule}" | |
92 | ## rebase patches | |
93 | echo "" | |
94 | echo "rebasing patchqueue on top of '${new_tag}'" | |
95 | git rebase "${new_tag}" | |
96 | cd "${top}" | |
97 | ||
98 | ## regenerate exported patch queue | |
99 | echo "" | |
100 | "${top}/debian/scripts/export-patchqueue" "${kernel_submodule}" "${kernel_patchdir}" "${new_tag}" || error_exit "failed to export patchqueue" | |
101 | ||
102 | cleanup_pq_branch | |
103 | cd "${top}" | |
104 | pq_branch= | |
105 | fi | |
106 | ||
107 | cd "${kernel_submodule}" | |
108 | echo "" | |
109 | echo "checking out '${new_tag}' in submodule" | |
110 | git checkout --quiet "${new_tag}" | |
111 | cd "${top}" | |
112 | ||
113 | echo "" | |
114 | echo "committing results" | |
115 | git commit --verbose -s -m "update sources to ${new_tag}" -m "(generated with debian/scripts/import-upstream-tag)" "${kernel_submodule}" | |
116 | if [[ -n "$rebase" ]]; then | |
117 | git add "${kernel_patchdir}" | |
118 | git commit --verbose -s -m "rebase patches on top of ${new_tag}" -m "(generated with debian/scripts/import-upstream-tag)" "${kernel_patchdir}" | |
119 | fi |