From a8e86e247342b9a89a1393ad38add79b278525cd Mon Sep 17 00:00:00 2001 From: Thomas Fini Hansen Date: Tue, 19 Nov 2024 08:39:31 +0100 Subject: [PATCH] Handle no ~/.gitconfig If the file doesn't exist, Docker will create a root owned empty directory instead, which will mess any git command run on the host. --- tools/dplsh/dplsh.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/dplsh/dplsh.sh b/tools/dplsh/dplsh.sh index b3abed83..aeb18297 100755 --- a/tools/dplsh/dplsh.sh +++ b/tools/dplsh/dplsh.sh @@ -216,13 +216,20 @@ if [[ -z "${DPLSH_NON_INTERACTIVE:-}" ]]; then ADDITIONAL_ARGS+=(-i) fi +# Only mount in ${HOME}/.gitconfig if it exists. Otherwise docker will +# create an empty, root owned {HOME}/.gitconfig which will make git +# very unhappy. +if [[ -f "${HOME}/.gitconfig" ]] ; then + GITCONFIG+=(-v "${HOME}/.gitconfig:/opt/.gitconfig-host:ro") +fi + docker run --hostname=dplsh \ --rm \ "${ADDITIONAL_ARGS[@]}" \ -t \ -e "HOST_UID=$(id -u)" \ -v "${HOME}/.azure:/opt/.azure-host:ro" \ - -v "${HOME}/.gitconfig:/opt/.gitconfig-host:ro" \ + "${GITCONFIG[@]}" \ -v "${HOME}/.ssh:/opt/.ssh-host:ro" \ -v "${SHELL_ROOT}:/home/dplsh/host_mount" \ -w "/home/dplsh/host_mount/${CHDIR}" \