From d97346f1ceb2f86d0b26fb72cf18647a074bb639 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Mon, 31 Jul 2023 20:56:57 +0200 Subject: [PATCH] utils/docker-run: fix running when CWD is not MAIN_DIR Commit 90790790925c (utils/docker-run: fix support for git-worktrees) got last-minute changes when it was applied, and the case when the current working directory is not the top of the current working copy got broken. Fix that by duplicating (and thus reinstating) the 'cd MAIN_DIR' to match what is done when retrieving the git-common-dir. Fixes: 90790790925c Reported-by: Brandon Maier Signed-off-by: Yann E. MORIN (cherry picked from commit 5b559109eeeec19e6e33c82712690aec89dcb562) Signed-off-by: Peter Korsgaard --- utils/docker-run | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/docker-run b/utils/docker-run index b201d28289..ab95e61e84 100755 --- a/utils/docker-run +++ b/utils/docker-run @@ -27,9 +27,10 @@ declare -a docker_opts=( # .git directory. if [ "${GIT_DIR}" ]; then # GIT_DIR in the main working copy (when git supports worktrees) will - # be just '.git', but 'docker run' needs an absolute path. If it's an - # absolute path already (in a wordir), then that's a noop. - GIT_DIR="$(readlink -e "${GIT_DIR}")" + # be just '.git', but 'docker run' needs an absolute path. If it is + # 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}" ) fi