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