lorikeet-heimdal: improve import-lorikeet.sh for the toplevel build
[metze/heimdal/wip.git] / rebase-lorikeet.sh
1 #!/bin/sh
2 #
3 # Usage copy import-lorikeet.sh and rebase-lorikeet.sh
4 # into an empty directory maybe call it update-heimdal
5 # and don't use it for any other work than importing lorikeet heimdal
6 # into samba.
7 #
8 # These parameter might be changed:
9 #
10 # heimdal_my_wip_name
11 # heimdal_my_wip_url
12 # old_lorikeet_branch
13 #
14 # you can pass skip_fetch=yes and/or skip_rebase=yes as env vars
15 #
16
17 # this needs to be reachable from
18 old_lorikeet_branch=$1
19
20 DATE=`date --utc +%Y%m%d%H%M`
21
22 heimdal_my_wip_name="heimdal-local"
23 heimdal_my_wip_url="/data/heimdal"
24
25 if test x"$old_lorikeet_branch" = x""; then
26         old_lorikeet_branch="heimdal-metze-wip/lorikeet-heimdal"
27 fi
28
29 tmp_lorikeet_branch="lorikeet-heimdal-tmp"
30 new_lorikeet_branch="lorikeet-heimdal-${DATE}"
31
32 bailout() {
33         exit $1;
34 }
35
36 # 1. create a local heimdal repository in the heimdal subdir
37
38 heimdal_init() {
39         test -d heimdal || {
40                 mkdir heimdal || bailout $?
41                 pushd heimdal
42                 git init || bailout $?
43                 git remote add heimdal-git git://github.com/heimdal/heimdal.git
44                 git remote add lorikeet-heimdal-abartlet ssh://git.samba.org/data/git/abartlet/lorikeet-heimdal.git/.git
45                 git remote add lorikeet-heimdal ssh://git.samba.org/lorikeet-heimdal.git
46                 git remote add ${heimdal_my_wip_name} ${heimdal_my_wip_url}
47                 popd
48         }
49
50         return 0;
51 }
52
53 # 2. bring the repository uptodate
54 heimdal_fetch() {
55         test x"$skip_fetch" = x"yes" || {
56                 pushd heimdal
57                 git fetch heimdal-git || bailout $?
58                 git fetch lorikeet-heimdal-abartlet || bailout $?
59                 git fetch ${heimdal_my_wip_name} || bailout $?
60                 popd
61         }
62
63         return 0;
64 }
65
66 # 3. rebase the old_lorikeet_branch on top of heimdals trunk
67 heimdal_rebase() {
68         test x"$skip_rebase" = x"yes" || {
69                 pushd heimdal
70                 echo "git update-ref"
71                 git update-ref refs/heads/$tmp_lorikeet_branch $old_lorikeet_branch || bailout $?
72                 echo "git checkout"
73                 git checkout $tmp_lorikeet_branch || bailout $?
74                 echo "git reset --hard HEAD"
75                 git reset --hard HEAD
76                 echo "git rebase"
77                 git rebase heimdal-git/master || {
78                         echo "PS1=\"'git-rebase shell'>\"" > ../.bashrc.heimdal_rebase
79                         bash --rcfile ../.bashrc.heimdal_rebase || {
80                                 ret=$?
81                                 echo "git rebase --abort (just in case)"
82                                 git rebase --abort
83                                 bailout $ret
84                         }
85                 }
86                 echo "git rebase --abort (just in case)"
87                 git rebase --abort
88                 echo "Now build and test the lorikeet heimdal tree"
89                 echo "and exit with 0 if you want to create a $new_lorikeet_branch branch"
90                 echo ""
91                 echo "PS1=\"'build shell'>\"" > ../.bashrc.heimdal_build
92                 bash --rcfile ../.bashrc.heimdal_build || bailout $?
93                 git branch $new_lorikeet_branch $tmp_lorikeet_branch || bailout $?
94                 echo "branch $new_lorikeet_branch created"
95                 popd
96         }
97
98         return 0;
99 }
100
101 heimdal_init
102 heimdal_fetch
103 heimdal_rebase