Emacsg: add bin/borg-bootstrap script

See the commentary at the beginning of the script for usage
instructions.  Starting with the next commit `make bootstrap'
will use it.
This commit is contained in:
Jonas Bernoulli 2016-11-28 19:24:26 +01:00
parent 98b6613d11
commit d079306f51

97
bin/borg-bootstrap Executable file
View File

@ -0,0 +1,97 @@
#!/bin/sh
# Copyright (C) 2016 Jonas Bernoulli
#
# Author: Jonas Bernoulli <jonas@bernoul.li>
# License: GPL v3 <https://www.gnu.org/licenses/gpl-3.0.txt>
# Commentary:
# This script is a replacement for `git submodule update'. The
# main differences are that this script resets the current branch
# if necessary instead of detaching HEAD and that it is capable of
# adding and configuring additional remotes.
# The following variables can be set in ".gitmodules":
#
# * submodule.DRONE.remote = NAME URL
#
# This variable specifies an additional remote named DRONE that is
# fetched from URL.
#
# * borg.collective = REMOTE
#
# This variable specifies the name used for remotes that reference
# a repository that has been patched by the collective. If a NAME
# matches REMOTE, then it is configured as the upstream of the
# current branch of the respective DRONE.
#
# * borg.pushDefault = DEFAULT
#
# This variable specifies a name used for push-remotes. If a NAME
# matches DEFAULT, then it is configured as the push-remote of the
# current branch of the respective DRONE.
# If an error occurs while `make bootstrap' runs this script, then
# fix the error(s) and run `bin/borg-bootstrap' directly, followed
# by `make build'.
hive_remote=$(git config -f .gitmodules borg.collective)
push_remote=$(git config -f .gitmodules borg.pushDefault)
git submodule--helper list |
while read mode sha1 stage path
do
name=$(git submodule--helper name "$path")
url=$(git config -f .gitmodules submodule."$name".url)
if test -e "$path" && ! test -e "$path"/.git
then
git submodule--helper clone --name "$name" --path "$path" --url "$url"
git config -f .gitmodules --get-all submodule."$name".remote |
while read remote remote_url
do
if ! test -e "$path"/.git
then
git submodule--helper clone \
--name "$name" \
--path "$path" \
--url "$remote_url" &&
git remote rename origin "$remote"
else
(
cd "$path"
git remote add "$remote" "$remote_url"
git fetch "$remote"
)
fi
if test -e "$path"/.git
then
(
cd "$path"
if test "$remote" = "$hive_remote"
then
git config branch.master.remote "$remote"
elif test "$remote" = "$push_remote"
then
git config remote.pushDefault "$remote"
fi
)
fi
done
if test -e "$path"/.git
then
(
cd "$path"
git reset --hard "$sha1" ||
echo >&2 "futile: checkout of '$sha1' into submodule path '$path' failed"
)
else
echo >&2 "futile: clone of any remote into submodule path '$path' failed"
fi
fi
done