From f4b798120b0eb43d3997aa9aefb8f54d47f2849f Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Wed, 9 Aug 2023 23:24:46 +0200 Subject: [PATCH] utils/docker-run: introduce sorted list of mountpoints For now, we only ever mount two mountpoints, the main directory (i.e. the working copy), and the git directory. To pave the way for adding new mountpoints, we introduce a list of them, that we sort to ensure that we never mount a shallower mounpoint after a deeper one (that would shadow the deeper mountpoint). Signed-off-by: Yann E. MORIN Cc: Thomas Petazzoni --- utils/docker-run | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/docker-run b/utils/docker-run index ab95e61e84..2f689a1fbd 100755 --- a/utils/docker-run +++ b/utils/docker-run @@ -17,10 +17,11 @@ declare -a docker_opts=( -i --rm --user "$(id -u):$(id -g)" - --mount "type=bind,src=${MAIN_DIR},dst=${MAIN_DIR}" --workdir "${MAIN_DIR}" ) +declare -a mountpoints=( "${MAIN_DIR}" ) + # Empty GIT_DIR means that we are not in a workdir, *and* git is too old # to know about worktrees, so we're not in a worktree either. So it means # we're in the main git working copy, and thus we don't need to mount the @@ -31,9 +32,14 @@ if [ "${GIT_DIR}" ]; then # not absolute, GIT_DIR is relative to MAIN_DIR. If it's an absolute # path already (in a wordir), then that's a noop. GIT_DIR="$(cd "${MAIN_DIR}"; readlink -e "${GIT_DIR}")" - docker_opts+=( --mount "type=bind,src=${GIT_DIR},dst=${GIT_DIR}" ) + mountpoints+=( "${GIT_DIR}" ) fi +# shellcheck disable=SC2013 # can't use while-read because of the assignment +for dir in $(printf '%s\n' "${mountpoints[@]}" |LC_ALL=C sort -u); do + docker_opts+=( --mount "type=bind,src=${dir},dst=${dir}" ) +done + if tty -s; then docker_opts+=( -t ) fi