enter_chroot: handle older git versions
The --type=path option was added in git-2.18.0 (Jun 2018), and not
everyone keeps their system up-to-date. Use --type=path only when
we detect that ~ is being used so we support old/new versions well.
BUG=chromium:1025578
TEST=`cros_sdk` copies in gitcookies now
Change-Id: I78741332f19fefa89869a4216769c0fab7f62abe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/1966379
Reviewed-by: Sean Abraham <seanabraham@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh
index 2ea6cc0..9394eee 100755
--- a/sdk_lib/enter_chroot.sh
+++ b/sdk_lib/enter_chroot.sh
@@ -287,6 +287,18 @@
git config "$@"
}
+# The --type=path option is new to git-2.18 and not everyone upgrades.
+# But not everyone uses the ~ prefix, so try that option if needed.
+git_config_path() {
+ local out
+ out=$(git_config "$@")
+ if [[ "${out:0:1}" == "~" ]]; then
+ git_config --type path "$@"
+ else
+ echo "${out}"
+ fi
+}
+
setup_git() {
# Copy .gitconfig into chroot so repo and git can be used from inside.
# This is required for repo to work since it validates the email address.
@@ -309,7 +321,7 @@
# Copy the gitcookies file, updating the user's gitconfig to point to it.
local gitcookies
- gitcookies="$(git_config --type path -f "${chroot_gitconfig}" \
+ gitcookies="$(git_config_path --file "${chroot_gitconfig}" \
--get http.cookiefile)"
if [[ $? -ne 0 ]]; then
# Try the default location anyway.
@@ -394,7 +406,7 @@
setup_mount "${FLAGS_trunk}" "--rbind" "${CHROOT_TRUNK_DIR}"
debug "Setting up referenced repositories if required."
- REFERENCE_DIR=$(git_config --file \
+ REFERENCE_DIR=$(git_config_path --file \
"${FLAGS_trunk}/.repo/manifests.git/config" \
repo.reference)
if [ -n "${REFERENCE_DIR}" ]; then