901db5af73906f3ec7ac7f3d950ec98664cc41a5
[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 ];then
9   echo >&2 "Syntax: $0 branch-list-delimited-by-dashes"
10   exit 1
11 fi
12 if [ -f origin ];then
13   origin="`cat origin`"
14 else
15   origin="origin/master"
16 fi
17 base=$origin
18 gerrit=true
19 if git branch -D gerrit;then
20   git checkout $origin
21   git checkout -b gerrit
22 else
23   gerrit=false
24 fi
25 for elem in $(echo "$1"|tr '-' ' ');do
26   if [ "$base" = $origin ];then
27     next="$elem"
28   else
29     next="$base-$elem"
30   fi
31   git checkout "$next"
32   git merge --no-edit "$base"
33   if $compile;then
34     make
35   fi
36   if [ -e "$next".patch ];then
37     echo -e '/^--- /,$d\nw'|ed "$next".patch || :
38   fi
39   git diff                    "$base" "$next" --|diffdecvs >>"$next".patch
40   git diff -U9999999 --binary "$base" "$next" --            >"$next".Upatch
41   if $gerrit;then
42     cp "$next".patch dashtopatch.patch
43     echo -e '/^--- /,$d\nw'|ed dashtopatch.patch
44     git checkout gerrit
45     patch -p1 <"$next".patch
46     git commit -a -F dashtopatch.patch
47     rm -f dashtopatch.patch
48   fi
49   base="$next"
50 done
51 git checkout "$next"
52 echo OK