]> git.ozlabs.org Git - next-scripts/blob - merge_fix
use the local do_build script
[next-scripts] / merge_fix
1 #!/bin/bash
2
3 bin_dir="$(dirname $0)"
4
5 LOG_FILE="../merge.log"
6 build_host="ka2"
7 build_dir="/scratch/sfr/next"
8 [ "$NEXT_BUILD_HOST" ] && build_host="$NEXT_BUILD_HOST"
9 [ "$NEXT_BUILD_DIR" ] && build_dir="$NEXT_BUILD_DIR"
10
11 no_build=false
12 [ "$1" = "-n" ] && {
13         shift
14         no_build=true
15 }
16 patch="$1"
17 shift
18 [ -f "$patch" ] || {
19         echo "patch does not exist" 1>&2
20         exit 1
21 }
22 [ -n "$1" ] && {
23         build_host="$1"
24         shift
25 }
26 [ -n "$1" ] && {
27         build_dir="$1"
28         shift
29 }
30
31 export NEXT_BUILD_HOST="$build_host"
32 export NEXT_BUILD_DIR="$build_dir"
33
34 log()
35 {
36         echo "$@" | tee -a $LOG_FILE
37 }
38
39 execute()
40 {
41         log "$" $@
42         $@ 2>&1 | tee -a $LOG_FILE
43         return ${PIPESTATUS[0]}
44 }
45
46 old_head=$(git rev-parse HEAD)
47 execute git am -3 "$patch" || {
48         echo "git am failed" 1>&2
49         bash -i || exit
50 }
51 new_head=$(git rev-parse HEAD)
52 [ "$old_head" = "$new_head" ] && {
53         echo "hmmm, looks like the patch was already applied or is unneeded"
54         exit 0
55 }
56 [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] && {
57         echo "hmmm, committed soemthing, but diff is empty" 1>&2
58         bash -i || exit
59 }
60
61 GIT_EDITOR=: execute git reset 'HEAD^' || {
62         echo "git reset failed" 1>&2
63         bash -i || exit
64 }
65 execute git add -A . || {
66         echo "git add failed" 1>&2
67         bash -i || exit
68 }
69 GIT_EDITOR=: execute git commit -v -a --amend || {
70         echo "git commit failed" 1>&2
71         bash -i || exit
72 }
73
74 $no_build && exit 0
75
76 git push -f "$build_host":"$build_dir" master:refs/heads/next || {
77         echo git push failed 1>&2
78         bash -i || exit
79 }
80
81 "$bin_dir/do_build" || {
82         echo Build failed 1>&2
83         bash -i || exit
84 }
85
86 exit 0