]> git.ozlabs.org Git - next-scripts/blob - do_merge
do_merge: sprinkle notify-send's around to help the operator
[next-scripts] / do_merge
1 #!/bin/bash
2
3 no_build=false
4 start_from=""
5
6 [ "$1" = "-n" ] && {
7         shift
8         no_build=true
9 }
10 [ "$1" = "-s" ] && {
11         shift
12         start_from="$1"
13         [ -z "$start_from" ] && {
14                 echo "-s requires a start tree" 1>&2
15                 exit 1
16         }
17         shift
18 }
19
20 . "$(dirname $0)/common.sh"
21
22 log()
23 {
24         echo "$@" | tee -a $LOG_FILE
25 }
26
27 execute()
28 {
29         log "$" $@
30         $@ 2>&1 | tee -a $LOG_FILE
31         return ${PIPESTATUS[0]}
32 }
33
34 do_rebase()
35 {
36         rbase=${1#*/}
37         rbase=${rbase%%:*}
38         rtop=${1#*:}
39         rbid=$(git rev-parse $2/$rbase)
40         rtid=$(git rev-parse $2/$rtop)
41         [ "$rbid" = "$rtid" ] && {
42                 echo Empty tree
43                 return
44         }
45         [ "$(git rev-list HEAD..$2/$rtop)" ] || {
46                 echo Already merged
47                 return
48         }
49         execute git clone -s -l -n -q . ../rebase-tmp || {
50                 echo Clone failed 1>&2
51                 bash -i || exit
52         }
53         log '$' cd ../rebase-tmp
54         cd ../rebase-tmp
55         execute git fetch --no-tags ../next refs/remotes/$2/$rtop:$2/$rtop || {
56                 echo Fetch of top failed 1>&2
57                 bash -i || exit
58         }
59         execute git fetch --no-tags ../next refs/remotes/$2/$rbase:$2/$rbase || {
60                 echo Fetch of base failed 1>&2
61                 bash -i || exit
62         }
63         execute git checkout $2/$rtop || {
64                 echo Checkout of top failed 1>&2
65                 bash -i || exit
66         }
67         execute git rebase --onto master $2/$rbase || {
68                 echo Rebase failed 1>&2
69                 bash -i || exit
70         }
71         log '$' cd ../next
72         cd ../next
73         execute git pull -f ../rebase-tmp $2/$rtop || {
74                 echo Pull failed 1>&2
75                 echo $h >>../merge.debug
76                 git diff >>../merge.debug 2>&1
77                 git diff 2>&1 | egrep -q '<<<<<|^\*' && {
78                         bash -i || exit
79                 }
80         }
81         execute rm -rf ../rebase-tmp
82 }
83
84 [ -n "$start_from" ] || {
85         cp /dev/null $LOG_FILE
86         execute date
87         execute git checkout master
88         execute git reset --hard stable
89         printf 'Name\t\tSHA1\n----\t\t----\n' > $SHA1_FILE
90
91 }
92
93 heads=$(grep -v '^#' $CTRL_FILE | awk -F '\t' '$2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); }')
94
95 need_build=false
96
97 for h in $heads; do
98         tree=${h%%/*}
99
100         [ -n "$start_from" ] && {
101                 if [ "$tree" = "$start_from" ]; then
102                         start_from=""
103                 else
104                         continue
105                 fi
106         }
107
108         hlog=$(git log -1 --oneline ${h/\/*://}) 2>/dev/null
109         old_head=$(git rev-parse HEAD)
110         [ -f "../pre-merge/$tree" ] && {
111                 for p in $(cat "../pre-merge/$tree"); do
112                         "$bin_dir/do_patch" -n "$p" || {
113                                 notify-send -u critical -t 0 "premerge patch failed"
114                                 bash -i || exit
115                         }
116                 done
117         }
118         log Merging $h "($hlog)"
119         case "$h" in
120         *:*)
121                 do_rebase $h $tree
122                 ;;
123         *)
124                 execute git merge $h || {
125                         echo Merge failed 1>&2
126                         echo $h >>../merge.debug
127                         git diff >>../merge.debug 2>&1
128                         um_files=$(git diff 2>&1 | sed -n 's/^\* Unmerged path //p')
129                         [ "$um_files" ] && [ -f "../merge-files/$tree" ] && {
130                                 rm_files=$(grep -F "$um_files" "../merge-files/$tree")
131                                 [ "$rm_files" ] &&
132                                         "$bin_dir/do_rm" $rm_files
133                         }
134                         git diff 2>&1 | egrep -q '<<<<<|^\*' && {
135                                 notify-send -u critical -t 0 "merge failed"
136                                 bash -i || exit
137                         }
138 #                       [ "$(git status --porcelain)" ] && {
139                                 GIT_EDITOR=: execute git commit -v -a
140                                 execute git diff -M --stat --summary 'HEAD^..'
141 #                       }
142                 }
143                 ;;
144         esac
145         [ -f "../merge-fixes/$tree" ] && {
146                 for p in $(cat "../merge-fixes/$tree"); do
147                         "$bin_dir/merge_fix" -n "$p" || {
148                                 notify-send -u critical -t 0 "post merge patch failed"
149                                 bash -i || exit
150                         }
151                 done
152         }
153         tab="\t"
154         [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
155         printf "%s$tab%s\n" $tree $(git rev-parse "${h/\/*://}") >> $SHA1_FILE
156         $no_build && continue
157         $need_build || {
158                 # See if we need to build after merging this tree
159                 new_head=$(git rev-parse HEAD)
160                 [ "$old_head" = "$new_head" ] ||
161                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
162                                 need_build=true
163         }
164         $need_build ||
165                 continue
166         do_build=$(grep -v '^#' $CTRL_FILE | awk -F '   ' '$3=="'$tree'" { print $6; }')
167         [ "$do_build" = "yes" ] ||
168                 continue
169         git push -f "$build_host":"$build_dir" master:refs/heads/next || {
170                 echo git push failed 1>&2
171                 notify-send -u critical -t 0 "push failed"
172                 bash -i || exit
173         }
174         "$bin_dir/do_build" || {
175                 echo Build failed 1>&2
176                 notify-send -u critical -t 0 "build failed"
177                 bash -i || exit
178         }
179         need_build=false
180 done
181
182 exit 0