]> git.ozlabs.org Git - next-scripts/blob - merge_fix
merge_fix: cope with fixup patches no longer applying
[next-scripts] / merge_fix
1 #!/bin/bash
2
3 LOG_FILE="../merge.log"
4 build_host="sprygo"
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 [ -f "$patch" ] || {
15         echo "patch does not exist" 1>&2
16         exit 1
17 }
18 [ -n "$2" ] && build_host="$2"
19
20 log()
21 {
22         echo "$@" | tee -a $LOG_FILE
23 }
24
25 execute()
26 {
27         log "$" $@
28         $@ 2>&1 | tee -a $LOG_FILE
29         return ${PIPESTATUS[0]}
30 }
31
32 old_head=$(git rev-parse HEAD)
33 execute git am -3 "$patch" || {
34         echo "git am failed" 1>&2
35         bash -i || exit
36 }
37 new_head=$(git rev-parse HEAD)
38 [ "$old_head" = "$new_head" ] && {
39         echo "hmmm, looks like the patch was already applied or is unneeded"
40         exit 0
41 }
42 [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] && {
43         echo "hmmm, committed soemthing, but diff is empty" 1>&2
44         bash -i || exit
45 }
46
47 GIT_EDITOR=: execute git reset 'HEAD^' || {
48         echo "git reset failed" 1>&2
49         bash -i || exit
50 }
51 execute git add . || {
52         echo "git add failed" 1>&2
53         bash -i || exit
54 }
55 GIT_EDITOR=: execute git commit -v -a --amend || {
56         echo "git commit failed" 1>&2
57         bash -i || exit
58 }
59
60 $no_build && exit 0
61
62 rsync -avH --exclude .git --delete . "$build_host":"$build_dir"/. || {
63         echo Rsync failed 1>&2
64         bash -i || exit
65 }
66
67 echo "Building using $build_cmd on $build_host"
68 ssh "$build_host" "$build_cmd" || {
69         echo Build failed 1>&2
70         bash -i || exit
71 }
72
73 exit 0