From 9151c446583d0e4fd866c6d951271d6eb36cbc6c Mon Sep 17 00:00:00 2001 From: Filip Hejsek Date: Mon, 1 Jul 2024 16:10:24 +0000 Subject: [PATCH] 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. --- scripts/libmakepkg/source/git.sh.in | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/libmakepkg/source/git.sh.in b/scripts/libmakepkg/source/git.sh.in index 5f700a09..35e31fc1 100644 --- a/scripts/libmakepkg/source/git.sh.in +++ b/scripts/libmakepkg/source/git.sh.in @@ -56,15 +56,18 @@ download_git() { fi elif (( ! HOLDVER )); then 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 - 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 error "$(gettext "%s is not a clone of %s")" "$dir" "$url" plainerr "$(gettext "Aborting...")" exit $E_NOT_A_CLONE_OF fi 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 warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git" fi @@ -73,7 +76,7 @@ download_git() { # Sanitize the cloned repo # $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 - 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" echo "* -export-subst -export-ignore" > "$MAKEPKG_GIT_DIR/info/attributes" }