From e017a5975cfe3e53670848bd45c982524d6745af Mon Sep 17 00:00:00 2001 From: soloturn Date: Sun, 20 Mar 2022 10:35:09 +0100 Subject: [PATCH] makepkg: Add GITFLAGS environmental variable to customise checkout The default flag used to clone a git repository when using makepkg is "--mirror". However, when working with huge repositories, the use of different flags during cloning can allow an faster checkout. For example, using "--filter=blob:none" allows for small checkouts, at the expense of requiring downloads during the build stage if anything but the HEAD commit is used for the build. In addition, this example would serve as a replacement for the often requested (but broken) addition of --depth=1. Add support for the environment variable GITFLAG to pass flags for the git clone command. Note that this overrides the default rather than adding to it in order to prevent incompatibilities. --- doc/makepkg.8.asciidoc | 4 ++++ scripts/libmakepkg/source/git.sh.in | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/makepkg.8.asciidoc b/doc/makepkg.8.asciidoc index 38032e7b..d023b038 100644 --- a/doc/makepkg.8.asciidoc +++ b/doc/makepkg.8.asciidoc @@ -287,6 +287,10 @@ Environment Variables **BUILDTOOLVER=**"":: The version of the '$BUILDTOOL' used. +**GITFLAGS**:: + The options to pass when checking out git sources, replacing the default + "--mirror". + Configuration ------------- See linkman:makepkg.conf[5] for more details on configuring makepkg using the diff --git a/scripts/libmakepkg/source/git.sh.in b/scripts/libmakepkg/source/git.sh.in index bcff958d..f809cc9e 100644 --- a/scripts/libmakepkg/source/git.sh.in +++ b/scripts/libmakepkg/source/git.sh.in @@ -46,9 +46,12 @@ download_git() { url=${url%%#*} url=${url%%\?*} + # Allow overriding of options passed to git clone command, e.g. --filter=blob:none for partial cloning of big repos + local gitflags=${GITFLAGS:---mirror} + if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git" - if ! git clone --mirror "$url" "$dir"; then + if ! git clone $GITFLAGS "$url" "$dir"; then error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git" plainerr "$(gettext "Aborting...")" exit 1