Makefile: remotes: Delete obsolete remote
[sunny256-utils.git] / old-git
blob4984fb31ad442007c6ab106bb6f3e066440a4f4d
1 #!/usr/bin/env bash
3 #=======================================================================
4 # old-git
5 # File ID: 352732aa-2e4d-11e5-bd5f-fefdb24f8e10
7 # Compile and install git(1).
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=old-git
14 VERSION=0.4.0
16 ARGS="$(getopt -o "\
20 " -l "\
21 help,\
22 no-net,\
23 quiet,\
24 verbose,\
25 version,\
26 " -n "$progname" -- "$@")"
27 test "$?" = "0" || exit 1
28 eval set -- "$ARGS"
30 opt_help=0
31 opt_no_net=0
32 opt_quiet=0
33 opt_verbose=0
34 while :; do
35 case "$1" in
36 (-h|--help) opt_help=1; shift ;;
37 (--no-net) opt_no_net=1; shift ;;
38 (-q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
39 (-v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
40 (--version) echo $progname $VERSION; exit 0 ;;
41 (--) shift; break ;;
42 (*) echo $progname: Internal error >&2; exit 1 ;;
43 esac
44 done
45 opt_verbose=$(($opt_verbose - $opt_quiet))
47 if test "$opt_help" = "1"; then
48 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
49 cat <<END
51 Compile and install git(1). Default action is to build from the newest
52 revision on 'master'. Another branch or tag can be specified as first
53 argument.
55 Usage: $progname [options] [branch]
57 Options:
59 -h, --help
60 Show this help.
61 --no-net
62 Don't fetch or push, use what's present in the local repo.
63 -q, --quiet
64 Be more quiet. Can be repeated to increase silence.
65 -v, --verbose
66 Increase level of verbosity. Can be repeated.
67 --version
68 Print version information.
70 END
71 exit 0
74 lockdir=$HOME/.Build-git.LOCK
76 myexit() {
77 rmdir $lockdir || echo $progname: $lockdir: Cannot remove lockdir >&2
78 exit $1
81 trap "myexit 1" INT TERM
82 mkdir $lockdir || {
83 echo $progname: $lockdir: Cannot create lockdir >&2
84 exit 1
87 rcfile=$HOME/.build-gitrc
88 origin_url=git://git.kernel.org/pub/scm/git/git.git
90 # Directory where the git build happens
91 builddir=$HOME/src/other/git/build-git
93 # Prefix to directory tree where git will be installed. You can change
94 # it to for example $HOME/local if you don’t have root access.
95 pref=/usr/local
97 # If you don’t have sudo rights or you don’t need it at the location in
98 # the file system, clear the value of the $sudo variable
99 sudo=sudo
101 # Local name of remote master
102 local_master=master
104 # Name of remote master
105 remote_master=origin/master
107 # Set to 0 to skip ./configure and use Makefile in git.git instead
108 use_configure=1
109 configure_opts=
111 makeflags=
112 make_doc=1
113 make_info=1
114 run_tests=1
115 hname=$(hostname)
117 [ -e $rcfile ] && . $rcfile
119 if [ -n "$1" ]; then
120 local_master=$1
123 is_official_branch() {
124 echo -n $1 | grep -Eq '^(master|maint|next|pu|todo)$' &&
125 return 0 || return 1
128 fetch_remotes() {
129 git remote | grep -q '^origin$' || git remote add origin $origin_url
130 git remote | grep -q '^kernelorg$' ||
131 git remote add kernelorg git://git.kernel.org/pub/scm/git/git.git
132 git remote | grep -q '^gitster$' || {
133 git remote add gitster git://github.com/gitster/git.git
134 git config --add remote.gitster.fetch +refs/notes/*:refs/notes/*
136 git remote | grep -q '^gitlab$' ||
137 git remote add gitlab git@gitlab.com:sunny256/git.git
138 git remote | grep -q '^peff$' ||
139 git remote add peff git://github.com/peff/git.git
140 git remote | grep -q '^sunbase$' ||
141 git remote add sunbase \
142 sunny@sunbase.org:/home/sunny/repos/Git-other/git.git
143 if test "$opt_no_net" = "0"; then
144 echo ================= git fetch =================
145 echo ===== origin =====
146 until git fetch origin; do
147 echo $progname: Fetch error from origin, retrying >&2
148 sleep 2
149 done
150 # git fetch --all arrived in v1.6.6, and that’s too recent to use.
151 for f in $(git remote | grep -v '^origin$'); do
152 echo ===== $f =====
153 git fetch $f
154 done
155 for f in maint master next pu todo; do
156 git branch | cut -c 3- | grep -q ^$f\$ || git branch $f origin/$f
157 done
161 commit_tree() {
162 git log --color --graph --pretty=format:'%Cred%h %Cblue%p%Creset '\
163 '-%C(yellow)%d%Creset %s %Cgreen(%cd %Cblue%an%Cgreen)%Creset' \
164 --abbrev-commit $1
167 enable_sudo() {
168 until $sudo echo Password OK | grep -q "Password OK"; do
170 done
173 push_changes() {
174 if test "$opt_no_net" = "0"; then
175 for f in bellmann loc-repo passp sunbase gitlab rsync-net; do
176 git remote | grep -q "^$f\$" && {
177 echo ==== push changes to $f ====
179 done
180 for f in loc-repo passp sunbase rsync-net; do
181 git remote | grep -q "^$f\$" && {
182 echo ==== push tags to $f ====
184 done
185 echo ==== push finished ====
187 lpar_git
190 print_timestamp() {
191 date +"%Y-%m-%d %H:%M:%S%z"
194 update_branches() {
198 lpar_git() {
202 [ -z "`git --version | grep '^git version '`" ] && {
203 echo $progname: You need to have git installed to use this script. >&2
204 myexit 1
207 rmdir $builddir 2>/dev/null
208 if [ ! -d $builddir/. ]; then
209 mkdir -p $builddir || {
210 echo $progname: $builddir: Cannot create directory
211 myexit 1
213 rmdir $builddir
214 echo ================= git clone =================
215 git clone $origin_url $builddir
216 cd $builddir || { echo $progname: $builddir: Cannot chdir >&2; myexit 1; }
217 git config lpar.name git
218 for f in maint next pu todo; do
219 git branch -t $f origin/$f || {
220 echo $progname: $f: Could not create branch >&2
221 myexit 1
223 done
225 cd $builddir || { echo $progname: $builddir: Cannot chdir >&2; myexit 1; }
226 GIT_PAGER=cat git status --porcelain | grep . && {
227 echo $progname: $builddir is not clean, aborting >&2
228 myexit 1
230 curr_git_ver=$(
231 cd $builddir &&
232 (git tag | grep compiled-$hname-2 | tail -1) || echo UNKNOWN
234 lpar_git
236 echo
237 echo Variables:
238 echo
239 echo "curr_git_ver = \"$curr_git_ver\" ($(
240 cd $builddir
241 git describe --long --match 'v[12]*' $curr_git_ver
243 echo "rcfile = \"$rcfile\" ($([ -e $rcfile ] || echo -n "not ")found)"
244 echo "builddir = \"$builddir\""
245 echo "pref = \"$pref\""
246 echo "sudo = \"$sudo\""
247 echo "local_master = \"$local_master\""
248 echo "remote_master = \"$remote_master\""
249 echo "makeflags = \"$makeflags\""
250 echo "make_doc = \"$make_doc\""
251 echo "make_info = \"$make_info\""
252 echo "hname = \"$hname\""
253 echo "use_configure = \"$use_configure\""
254 echo "configure_opts = \"$configure_opts\""
255 echo
257 git checkout $local_master || { echo Cannot check out branch >&2; myexit 1; }
258 if [ ! -e GIT-VERSION-GEN ]; then
259 # Paranoia check
260 echo $progname: Didn’t find GIT-VERSION-GEN. That’s strange, aborting.
261 myexit 1
263 is_official_branch $local_master &&
264 destbranch=origin/$local_master || destbranch=$local_master
265 echo
266 if [ -n "$curr_git_ver" ]; then
267 echo ================= git status in `pwd` =================
268 GIT_PAGER=cat git status
269 echo
270 print_timestamp
271 unset choice
272 until [ "$choice" = "y" ]; do
273 echo
274 unset choice
275 echo $(git log --format=oneline $curr_git_ver..$destbranch | wc -l) \
276 "new commits available in range $curr_git_ver..$destbranch"
277 echo Going to compile git $(
278 git describe --long --match 'v[12]*' $destbranch
280 echo
281 echo If that looks okay to you, press \'y\' to start the build, or:
282 echo \'d\' to diff
283 echo \'ds\' to diff --stat
284 echo \'dw\' to word-diff
285 echo \'l\' to list log
286 echo \'lp\' to list log with patch
287 echo \'lt\' to list log with commit tree
288 echo \'lw\' to list log with patch using word diff
289 echo \'n\' to abort
290 echo \'p\' to push new commits
291 echo \'t\' to show commit tree
292 read choice
293 [ "$choice" = "d" ] && git diff $curr_git_ver $destbranch
294 [ "$choice" = "ds" ] && git diff --stat $curr_git_ver $destbranch
295 [ "$choice" = "dw" ] && git diff --word-diff $curr_git_ver $destbranch
296 [ "$choice" = "l" ] && git log --stat $curr_git_ver..$destbranch
297 [ "$choice" = "lp" ] && git log --patch $curr_git_ver..$destbranch
298 [ "$choice" = "lt" ] &&
299 git log --graph --stat $curr_git_ver..$destbranch
300 [ "$choice" = "lw" ] &&
301 git log --patch --word-diff $curr_git_ver..$destbranch
302 [ "$choice" = "n" ] && myexit 0
303 [ "$choice" = "p" ] && {
304 if test "$opt_no_net" = "0"; then
305 update_branches
306 push_changes
307 else
308 echo $progname: --no-net was specified, will not push >&2
311 [ "$choice" = "t" ] && commit_tree $curr_git_ver..$destbranch
312 done
313 else
314 unset choice
315 until [ "$choice" = "y" ]; do
316 echo -n Press \'y\' to start the build, or \'n\' to abort...
317 read choice
318 [ "$choice" = "n" ] && myexit 0
319 done
322 echo ================= git clean =================
323 git clean -fxd
324 echo ================= Update all branches =================
325 update_branches
326 vername=git.$local_master.`git describe --long --match 'v[12]*'`
327 dest=$pref/varprg/$vername
328 [ -d $dest/. ] && {
329 echo
330 echo "Sorry, no new git(1) for you this time."
331 echo You’ll have to stick with `git --version` for now.
332 push_changes
333 myexit 0
335 push_changes
336 if [ "$use_configure" = "1" ]; then
337 echo $progname: Creating ./configure
338 make configure
339 echo ==== ./configure --prefix=$dest $configure_opts
340 ./configure --prefix=$dest $configure_opts
342 if [ "$make_doc" = "1" ]; then
343 make_doc_str=doc
344 inst_doc_str="install-doc install-html"
345 else
346 make_doc_str=
347 inst_doc_str=
349 if [ "$make_info" = "1" ]; then
350 make_info_str=info
351 inst_info_str=install-info
352 else
353 make_info_str=
354 inst_info_str=
356 unset make_doc_str make_info_str inst_doc_str inst_info_str run_tests
357 echo Compiling $vername
358 echo "==== make prefix=$dest $makeflags all" \
359 "$make_doc_str $make_info_str \|\| myexit"
360 make prefix=$dest $makeflags all $make_doc_str $make_info_str || myexit
361 if test "$run_tests" = "1"; then
362 echo ==== make $makeflags test
363 make $makeflags test
365 echo
366 echo Ready to install $(./git --version) from branch \"$local_master\"
367 unset choice
368 until test "$choice" = "y"; do
369 echo
370 print_timestamp
371 echo -n If all tests succeeded, press y to continue...
372 read choice
373 done
374 enable_sudo
375 echo "==== $sudo make prefix=$dest" \
376 "$makeflags install $inst_doc_str $inst_info_str"
377 $sudo make prefix=$dest $makeflags install $inst_doc_str $inst_info_str
378 echo ================= make install finished =================
379 myexit 0