]> git.ozlabs.org Git - next-scripts/blob - do_merge
merg_old_version: push even if not building
[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 fix_up()
37 {
38         if [ -n "$1" ]; then
39                 linux-next-notify "$1"
40         fi
41         if [ -n "$2" ]; then
42                 printf '%s\n' "$2" 1>&2
43         fi
44         if ! bash -i; then
45                 exit
46         fi
47 }
48
49 if [ -z "$start_from" ]; then
50         cp /dev/null "$LOG_FILE"
51         execute date -R
52         execute git checkout master
53         execute git reset --hard stable
54         printf 'Name\t\tSHA1\n----\t\t----\n' > "$SHA1_FILE"
55 fi
56
57 heads=$(awk -F '\t' '
58         /^#/ { next; }
59         $2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); }
60         $2=="branch" { printf("branch/%s ", $1); }' "$CTRL_FILE")
61
62 need_build=false
63
64 for h in $heads; do
65         tree=${h%%/*}
66
67         if [ -n "$start_from" ]; then
68                 if [ "$tree" = "$start_from" ]; then
69                         start_from=""
70                 else
71                         continue
72                 fi
73         fi
74
75         if [ "$tree" = "branch" ]; then
76                 git branch -f "${h#branch/}"
77                 linux-next-notify "update branch $1"
78                 continue
79         fi
80
81         hlog=$(git log -1 --oneline "$h") 2>/dev/null
82         old_head=$(git rev-parse HEAD)
83         if [ -f "../pre-merge/$tree" ]; then
84                 while read -r p <&7; do
85                         if ! "$bin_dir/do_patch" -n "$p"; then
86                                 fix_up "premerge patch failed"
87                         fi 7<&-
88                 done 7<"../pre-merge/$tree"
89         fi
90         log Merging "$h" "($hlog)"
91         if ! execute git merge "$h"; then
92                 echo Merge failed 1>&2
93                 echo "$h" >>../merge.debug
94                 git diff >>../merge.debug 2>&1
95
96                 check_unmerged_files "$tree"
97
98                 if git diff 2>&1 | grep -E -q '<<<<<|^\*'; then
99                         if [ -f "../merge-fixes/$tree" ]; then
100                                 echo "Merge fixes exist for this tree:"
101                                 cat "../merge-fixes/$tree"
102                         fi
103                         fix_up "new conflict found merging $tree"
104                 fi
105 #               if [ "$(git status --porcelain)" ]; then
106                         if ! execute git commit --no-edit -v -a; then
107                                 fix_up "next commit failed for $tree"
108                         fi
109                         execute git diff -M --stat --summary 'HEAD^..'
110 #               fi
111         fi
112         if [ -f "../merge-fixes/$tree" ]; then
113                 while read -r p <&7; do
114                         if ! "$bin_dir/merge_fix" -n "$p"; then
115                                 fix_up "merge fix failed for $tree"
116                         fi 7<&-
117                 done 7<"../merge-fixes/$tree"
118         fi
119
120         tab=$'\t'
121         if [ "${#tree}" -le 8 ]; then
122                 tab=$'\t\t'
123         fi
124         printf '%s%s%s\n' "$tree" "$tab" "$(git rev-parse "$h^{}")" >> "$SHA1_FILE"
125
126         if $no_build; then
127                 continue
128         fi
129
130         if ! $need_build; then
131                 # See if we need to build after merging this tree
132                 if [ -n "$(git diff "$old_head"..)" ]; then
133                         need_build=true
134                 fi
135         fi
136         if ! $need_build; then
137                 continue
138         fi
139
140         do_build=$(awk -F '\t' '/^[^#]/ && $3=="'"$tree"'" { print $6; }' "$CTRL_FILE")
141         if [ "$do_build" != "yes" ]; then
142                 continue
143         fi
144
145         repo="${build_host:+$build_host:}${build_dir}"
146         if ! git push -f "$repo" master:refs/heads/next; then
147                 fix_up "push failed for $tree" "git push failed"
148         fi
149
150         if [ -x "../pre-build/$tree" ] &&
151            ! "../pre-build/$tree"; then
152                 fix_up "pre-build script failed for $tree" "Prebuild script failed"
153         fi
154         if ! "$bin_dir/do_build" "$tree"; then
155                 fix_up "build failed for $tree" "Build failed"
156         fi
157
158         need_build=false
159 done
160
161 exit 0