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.
This commit is contained in:
soloturn 2022-03-20 10:35:09 +01:00 committed by Allan McRae
parent 79bd512181
commit e017a5975c
2 changed files with 8 additions and 1 deletions

View file

@ -287,6 +287,10 @@ Environment Variables
**BUILDTOOLVER=**"<version>"::
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

View file

@ -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