What's in
[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 test -f /bin/dash || with_dash=
39 if test -z "$BUILDBASE"
40 then
41         if test -d "$inst_prefix/buildfarm"
42         then
43                 BUILDBASE="$inst_prefix/buildfarm"
44         elif test -d "../buildfarm"
45         then
46                 BUILDBASE=../buildfarm
47         else
48                 echo >&2 "Buildbase unknown"
49                 exit 1
50         fi
51 fi
52 test -n "$branches" || branches='next master maint pu jch'
53 test -n "$jobs" || jobs=-j2
54
55 for branch in $branches
56 do
57         echo "** $branch **"
58         revision=$(git show-ref -s --verify "refs/heads/$branch") || {
59                 echo "** No $branch"
60                 continue
61         }
62
63         if test ! -d "$BUILDBASE/$branch"
64         then
65                 if test -z "$bootstrap"
66                 then
67                         echo "** No $BUILDBASE/$branch"
68                         continue
69                 fi
70                 "$NWD" . "$BUILDBASE/$branch" $branch &&
71                 ln -s "$(pwd)/Meta" "$BUILDBASE/$branch/Meta" || {
72                         echo "** Failed to bootstrap $BUILDBASE/$branch"
73                         continue
74                 }
75         fi
76
77         private=$(git rev-parse -q --verify private-$branch 2>/dev/null)
78         case $? in 0|1) ;; *) exit $? ;; esac
79
80         if      test -f "$inst_prefix/git-$branch/bin/git" &&
81                 installed=$($inst_prefix/git-$branch/bin/git version) &&
82                 if version=$(expr "$installed" : '.*\.g\([0-9a-f]*\)$')
83                 then
84                         :
85                 elif version=v$(expr "$installed" : \
86                                 'git version \(.*\)\.rc[0-9]*$')
87                 then
88                         version="$version"-$(expr "$installed" : \
89                                 'git version .*\.\(rc[0-9]*\)$')
90                 else
91                         version=v$(expr "$installed" : 'git version \(.*\)')
92                 fi &&
93                 version=$(git rev-parse --verify "$version^0" 2>/dev/null) &&
94                 test "z$version" = "z$revision"
95         then
96                 echo "* up-to-date version \"$installed\" is already installed from $branch"
97                 test -n "$force" || continue
98         fi
99
100         (
101                 case "$branch, $branches " in
102                 jch,*' next '*)
103                         if git diff --quiet --exit-code jch next
104                         then
105                                 dotest=
106                         else
107                                 dotest=test
108                         fi
109                         ;;
110                 *)
111                         dotest=test ;;
112                 esac
113                 test -z "$notest" || dotest=
114
115                 cd "$BUILDBASE/$branch"
116                 git reset --hard  &&
117                 case "$(git symbolic-ref HEAD)" in
118                 "refs/heads/$branch")
119                         : ;;
120                 *)
121                         git checkout "$branch" &&
122                         git reset --hard || exit
123                 esac &&
124
125                 case "$private" in
126                 '')
127                         ;;
128                 ?*)
129                         git merge --squash --no-commit "$private" || {
130                                 echo >&2 "** Cannot apply private edition changes"
131                                 git reset --hard
132                         }
133                         ;;
134                 esac &&
135
136                 {
137                         test "z$with_dash" != 'zy' ||
138                         Meta/Make $M $test -- $jobs SHELL_PATH=/bin/dash $dotest
139                 } &&
140
141                 Meta/Make $M $test -- $jobs $dotest &&
142                 {
143                         test -n "$nodoc" ||
144                         Meta/Make $M -- doc install-doc
145                 } &&
146
147                 {
148                         test z$install = znoinstall ||
149                         Meta/Make $M -- install
150                 } || exit $?
151
152                 git reset --hard
153         ) || break;
154
155 done