+unset command_not_found_handle
[nethome.git] / bin / dashtopatch
1 #! /bin/sh
2 set -ex
3 compile=false
4 if [ "$1" = -c ];then
5   compile=true
6   shift
7 fi
8 if [ $# != 1 ] || ! echo "$1" | grep -q '-';then
9   echo >&2 "Syntax: $0 branch-list-delimited-by-dashes"
10   exit 1
11 fi
12 base="gdb/master"
13 gerrit=true
14 if git branch -D gerrit;then
15   git checkout gdb/master
16   git checkout -b gerrit
17 else
18   gerrit=false
19 fi
20 for elem in $(echo "$1"|tr '-' ' ');do
21   if [ "$base" = "gdb/master" ];then
22     next="$elem"
23   else
24     next="$base-$elem"
25   fi
26   git checkout "$next"
27   git merge "$base"
28   if $compile;then
29     make
30   fi
31   if [ -e "$next".patch ];then
32     echo -e '/^--- /,$d\nw'|ed "$next".patch || :
33   fi
34   git diff "$base" "$next"|diffdecvs >>"$next".patch
35   if $gerrit;then
36     cp "$next".patch dashtopatch.patch
37     echo -e '/^--- /,$d\nw'|ed dashtopatch.patch
38     git checkout gerrit
39     patch -p1 <"$next".patch
40     git commit -a -F dashtopatch.patch
41     rm -f dashtopatch.patch
42   fi
43   base="$next"
44 done
45 git checkout "$next"
46 echo OK