.vimrc: +vim-fugitive
[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 [ "$origin" != "master" ];then
37     if [ -e "$next".patch ];then
38       echo -e '/^--- /,$d\nw'|ed "$next".patch || :
39     fi
40     git diff                    "$base" "$next" --|diffdecvs >>"$next".patch
41     git diff -U9999999 --binary "$base" "$next" --            >"$next".Upatch
42   fi
43   if $gerrit;then
44     cp "$next".patch dashtopatch.patch
45     echo -e '/^--- /,$d\nw'|ed dashtopatch.patch
46     git checkout gerrit
47     patch -p1 <"$next".patch
48     git commit -a -F dashtopatch.patch
49     rm -f dashtopatch.patch
50   fi
51   base="$next"
52 done
53 git checkout "$next"
54 echo OK