]> git.ozlabs.org Git - next-scripts/blob - do_merge
do_merge: shellcheck cleanups
[next-scripts] / do_merge
1 #!/bin/bash
2
3 no_build=false
4 start_from=""
5
6 while getopts 'ns:' opt; do
7         case "$opt" in
8         n)
9                 no_build=true
10                 ;;
11         s)
12                 start_from="$OPTARG"
13                 ;;
14         *)
15                 exit 1
16                 ;;
17         esac
18 done
19 shift $((OPTIND - 1))
20
21 # shellcheck source=common.sh
22 source "$(dirname "$0")/common.sh"
23
24 log()
25 {
26         echo "$@" | tee -a "$LOG_FILE"
27 }
28
29 execute()
30 {
31         log "$" "$@"
32         "$@" 2>&1 | tee -a "$LOG_FILE"
33         return "${PIPESTATUS[0]}"
34 }
35
36 [ -n "$start_from" ] || {
37         cp /dev/null "$LOG_FILE"
38         execute date -R
39         execute git checkout master
40         execute git reset --hard stable
41         printf 'Name\t\tSHA1\n----\t\t----\n' > "$SHA1_FILE"
42
43 }
44
45 heads=$(awk -F '\t' '/^#/ { next; } $2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); } $2=="branch" { printf("branch/%s ", $1); }' "$CTRL_FILE")
46
47 need_build=false
48
49 for h in $heads; do
50         tree=${h%%/*}
51
52         [ -n "$start_from" ] && {
53                 if [ "$tree" = "$start_from" ]; then
54                         start_from=""
55                 else
56                         continue
57                 fi
58         }
59
60         [ "$tree" = "branch" ] && {
61                 git branch -f "${h#branch/}"
62                 continue
63         }
64
65         hlog=$(git log -1 --oneline "${h/\/*://}") 2>/dev/null
66         old_head=$(git rev-parse HEAD)
67         [ -f "../pre-merge/$tree" ] && {
68                 while read -r p <&7; do
69                         if ! "$bin_dir/do_patch" -n "$p"; then
70                                 linux-next-notify "premerge patch failed"
71                                 bash -i || exit
72                         fi 7<&-
73                 done 7<"../pre-merge/$tree"
74         }
75         log Merging "$h" "($hlog)"
76         execute git merge "$h" || {
77                 echo Merge failed 1>&2
78                 echo "$h" >>../merge.debug
79                 git diff >>../merge.debug 2>&1
80
81                 check_unmerged_files "$tree"
82
83                 git diff 2>&1 | grep -E -q '<<<<<|^\*' && {
84                         linux-next-notify "new conflict found merging $tree"
85                         if [ -f "../merge-fixes/$tree" ]; then
86                                 echo "Merge fixes exist for this tree:"
87                                 cat "../merge-fixes/$tree"
88                         fi
89                         bash -i || exit
90                 }
91 #               [ "$(git status --porcelain)" ] && {
92                         GIT_EDITOR=: execute git commit -v -a || {
93                                 linux-next-notify "next commit failed for $tree"
94                                 bash -i || exit
95                         }
96                         execute git diff -M --stat --summary 'HEAD^..'
97 #               }
98         }
99         [ -f "../merge-fixes/$tree" ] && {
100                 while read -r p <&7; do
101                         if ! "$bin_dir/merge_fix" -n "$p"; then
102                                 linux-next-notify "merge fix failed for $tree"
103                                 bash -i || exit
104                         fi 7<&-
105                 done 7<"../merge-fixes/$tree"
106         }
107         tab=$'\t'
108         [ "${#tree}" -le 8 ] && tab=$'\t\t'
109         printf '%s%s%s\n' "$tree" "$tab" "$(git rev-parse "${h/\/*://}^{}")" >> "$SHA1_FILE"
110         $no_build && continue
111         $need_build || {
112                 # See if we need to build after merging this tree
113                 new_head=$(git rev-parse HEAD)
114                 [ "$old_head" = "$new_head" ] ||
115                         [ "$(git diff "$old_head".. | wc -c)" -eq 0 ] ||
116                                 need_build=true
117         }
118         $need_build ||
119                 continue
120         do_build=$(awk -F '\t' '/^[^#]/ && $3=="'"$tree"'" { print $6; }' "$CTRL_FILE")
121         [ "$do_build" = "yes" ] ||
122                 continue
123         git push -f "${build_host}${build_host:+:}${build_dir}" master:refs/heads/next || {
124                 echo git push failed 1>&2
125                 linux-next-notify "push failed for $tree"
126                 bash -i || exit
127         }
128         [ -x "../pre-build/$tree" ] && {
129                 "../pre-build/$tree" || {
130                         echo Prebuild script failed 1>&2
131                         linux-next-notify "pre-build script failed for $tree"
132                         bash -i || exit
133                 }
134         }
135         "$bin_dir/do_build" "$tree" || {
136                 echo Build failed 1>&2
137                 linux-next-notify "build failed for $tree"
138                 bash -i || exit
139         }
140
141         need_build=false
142 done
143
144 exit 0