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