What's cooking
[git] / Dothem
1 #!/bin/sh
2
3 NWD=contrib/workdir/git-new-workdir
4
5 inst_prefix=$(
6         IFS=:
7         for p in $PATH
8         do
9                 probed=${p%/git-active/bin}
10                 if test "$probed" != "$p"
11                 then
12                         echo "$probed"
13                         exit
14                 fi
15         done
16         echo $HOME
17 )
18
19 force= with_dash= M= install= nodoc= notest= bootstrap= branches= jobs=
20 while   case "$1" in
21         --pedantic | --locale=* | --loose) M="$M $1" ;;
22         --force) force=$1 ;;
23         --dash) with_dash=y ;;
24         --noinstall) install=noinstall ;;
25         --nodoc) nodoc=y ;;
26         --notest) notest=y ;;
27         --test=*) test="$1" ;;
28         --bootstrap) bootstrap=y ;;
29         --base=*) BUILDBASE=${1#*=} ;;
30         --branches=*) branches=${1#*=} ;;
31         -j*) jobs=$1 ;;
32         -*) echo >&2 "Unknown option: $1"; exit 1 ;;
33         *) break ;;
34         esac
35 do
36         shift
37 done
38
39 sh -c 'asciidoc --version >/dev/null 2>&1' || nodoc=y
40
41 test -f /bin/dash || with_dash=
42 if test -z "$BUILDBASE"
43 then
44         if test -d "$inst_prefix/buildfarm"
45         then
46                 BUILDBASE="$inst_prefix/buildfarm"
47         elif test -d "../buildfarm"
48         then
49                 BUILDBASE=../buildfarm
50         else
51                 echo >&2 "Buildbase unknown"
52                 exit 1
53         fi
54 fi
55 test -n "$branches" || branches='next master maint jch pu'
56 test -n "$jobs" || jobs=-j2
57
58 for branch in $branches
59 do
60         echo "** $branch **"
61         revision=$(git show-ref -s --verify "refs/heads/$branch") || {
62                 echo "** No $branch"
63                 continue
64         }
65
66         if test ! -d "$BUILDBASE/$branch"
67         then
68                 if test -z "$bootstrap"
69                 then
70                         echo "** No $BUILDBASE/$branch"
71                         continue
72                 fi
73                 "$NWD" . "$BUILDBASE/$branch" $branch &&
74                 ln -s "$(pwd)/Meta" "$BUILDBASE/$branch/Meta" || {
75                         echo "** Failed to bootstrap $BUILDBASE/$branch"
76                         continue
77                 }
78         fi
79
80         private=$(git rev-parse -q --verify private-$branch 2>/dev/null)
81         case $? in 0|1) ;; *) exit $? ;; esac
82
83         if      test -f "$inst_prefix/git-$branch/bin/git" &&
84                 installed=$($inst_prefix/git-$branch/bin/git version) &&
85                 if version=$(expr "$installed" : '.*\.g\([0-9a-f]*\)$')
86                 then
87                         :
88                 elif version=v$(expr "$installed" : \
89                                 'git version \(.*\)\.rc[0-9]*$')
90                 then
91                         version="$version"-$(expr "$installed" : \
92                                 'git version .*\.\(rc[0-9]*\)$')
93                 else
94                         version=v$(expr "$installed" : 'git version \(.*\)')
95                 fi &&
96                 version=$(git rev-parse --verify "$version^0" 2>/dev/null) &&
97                 test "z$version" = "z$revision"
98         then
99                 echo "* up-to-date version \"$installed\" is already installed from $branch"
100                 test -n "$force" || continue
101         fi
102
103         (
104                 case "$branch, $branches " in
105                 jch,*' next '*)
106                         if git diff --quiet --exit-code jch next
107                         then
108                                 dotest=
109                         else
110                                 dotest=test
111                         fi
112                         ;;
113                 *)
114                         dotest=test ;;
115                 esac
116                 test -z "$notest" || dotest=
117
118                 cd "$BUILDBASE/$branch"
119                 git reset --hard  &&
120                 case "$(git symbolic-ref HEAD)" in
121                 "refs/heads/$branch")
122                         : ;;
123                 *)
124                         git checkout "$branch" &&
125                         git reset --hard || exit
126                 esac &&
127
128                 case "$private" in
129                 '')
130                         ;;
131                 ?*)
132                         git merge --squash --no-commit "$private" || {
133                                 echo >&2 "** Cannot apply private edition changes"
134                                 git reset --hard
135                         }
136                         ;;
137                 esac &&
138
139                 save=$(git rev-parse HEAD) &&
140                 {
141                         test "z$with_dash" != 'zy' ||
142                         Meta/Make $M $test -- $jobs SHELL_PATH=/bin/dash $dotest
143                 } &&
144
145                 Meta/Make $M $test -- $jobs $dotest &&
146                 {
147                         test -n "$nodoc" ||
148                         Meta/Make $M -- doc install-doc
149                 } &&
150
151                 {
152                         test z$install = znoinstall ||
153                         if test "$save" = "$(git rev-parse HEAD)"
154                         then
155                                 Meta/Make $M -- install
156                         else
157                                 echo >&2 "Head moved--not installing"
158                         fi
159                 } || exit $?
160
161                 git reset --hard
162         ) || break;
163
164 done