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