git.sh: try direct clone if cached git fails

normally, a project is cached at repo/PROJECT/, and
cloned from there to the final destination.

errors lead to a calling of $err, but this will result
in a return if done from inside a subshell, of non-zero
value, so use this to re-try with a 6th argument when
calling tmpclone().

in most cases, this fallback will never kick in, but
it will kick in resetting or patching the cached clone
fails; specifically, we are interested in the reset part.

a given project name may change repositories in lbmk at
a given time. if this happens, and the old one is cached,
the overall result of this patch is that lbmk will fall
back to the old behaviour, where git urls are tried
directly, without caching.

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2
Leah Rowe 2024-07-17 17:01:15 +01:00 committed by Leah Rowe
parent 03c9670fef
commit 3e2e5ecf5a
1 changed files with 5 additions and 3 deletions

View File

@ -100,18 +100,20 @@ fetch_submodule()
tmpclone()
{
repodir="repo/${1##*/}"
repodir="repo/${1##*/}" && [ $# -gt 5 ] && repodir="$3"
x_ mkdir -p "repo"
if [ -d "$repodir" ]; then
if [ -d "$repodir" ] && [ $# -lt 6 ]; then
git -C "$repodir" pull || sleep 3 || git -C "$repodir" pull \
|| sleep 3 || git -C "$repodir" pull :
else
git clone $1 "$repodir" || git clone $2 "$repodir" || \
$err "!clone $1 $2 $repodir $4 $5"
fi
git clone "$repodir" "$3" || $err "!clone $repodir $3"
(
[ $# -gt 5 ] || git clone "$repodir" "$3" || $err "!clone $repodir $3"
git -C "$3" reset --hard "$4" || $err "!reset $1 $2 $3 $4 $5"
git_am_patches "$3" "$5"
) || [ $# -gt 5 ] || tmpclone $@ retry; :
}
git_am_patches()