libmakepkg: Use git -c safe.bareRepository=all in bare repositories

Git commands can fail in bare repositories when global git config contains safe.bareRepository=explicit.
Some users set this option for increased security.
To be compatible with this configuration, explicitly set safe.bareRepository=all when invoking git in a bare repository.
This commit is contained in:
Filip Hejsek 2024-07-01 16:10:24 +00:00 committed by Allan McRae
parent 8d22f991f9
commit 9151c44658

View file

@ -56,15 +56,18 @@ download_git() {
fi fi
elif (( ! HOLDVER )); then elif (( ! HOLDVER )); then
cd_safe "$dir" cd_safe "$dir"
# When invoking git on a potentially bare repository, we should pass -c safe.bareRepository=all
# to avoid breaking when the option is globally set to explicit
# Make sure we are fetching the right repo # Make sure we are fetching the right repo
local remote_url="$(git config --get remote.origin.url)" local remote_url="$(git -c safe.bareRepository=all config --get remote.origin.url)"
if [[ "${url%%.git}" != "${remote_url%%.git}" ]] ; then if [[ "${url%%.git}" != "${remote_url%%.git}" ]] ; then
error "$(gettext "%s is not a clone of %s")" "$dir" "$url" error "$(gettext "%s is not a clone of %s")" "$dir" "$url"
plainerr "$(gettext "Aborting...")" plainerr "$(gettext "Aborting...")"
exit $E_NOT_A_CLONE_OF exit $E_NOT_A_CLONE_OF
fi fi
msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git" msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git"
if ! git fetch --all -p; then if ! git -c safe.bareRepository=all fetch --all -p; then
# only warn on failure to allow offline builds # only warn on failure to allow offline builds
warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git" warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git"
fi fi
@ -73,7 +76,7 @@ download_git() {
# Sanitize the cloned repo # Sanitize the cloned repo
# $GIT_DIR/info/attributes overrides .gitattributes, and thus no files in the repository # $GIT_DIR/info/attributes overrides .gitattributes, and thus no files in the repository
# can be altered by git features like export-subst or export-ignore # can be altered by git features like export-subst or export-ignore
local MAKEPKG_GIT_DIR="$(git -C "$dir" rev-parse --absolute-git-dir)" local MAKEPKG_GIT_DIR="$(git -c safe.bareRepository=all -C "$dir" rev-parse --absolute-git-dir)"
mkdir -p "$MAKEPKG_GIT_DIR/info" mkdir -p "$MAKEPKG_GIT_DIR/info"
echo "* -export-subst -export-ignore" > "$MAKEPKG_GIT_DIR/info/attributes" echo "* -export-subst -export-ignore" > "$MAKEPKG_GIT_DIR/info/attributes"
} }