From dd78036c63ddf9d9044400324dd3bcdfa9bb59c1 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Wed, 1 Jul 2020 08:03:59 -0700 Subject: [PATCH] Improve docker/bash.sh to handle git worktrees (#5970) * improve error code when git ls-files fails * fix docker/bash to handle git worktrees --- docker/bash.sh | 10 ++++++++++ tests/lint/check_file_type.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docker/bash.sh b/docker/bash.sh index 008aa6a..a88951f 100755 --- a/docker/bash.sh +++ b/docker/bash.sh @@ -76,12 +76,22 @@ echo "" echo "Running '${COMMAND[@]}' inside ${DOCKER_IMAGE_NAME}..." +# When running from a git worktree, also mount the original git dir. +EXTRA_MOUNTS=( ) +if [ -f "${WORKSPACE}/.git" ]; then + git_dir=$(cd ${WORKSPACE} && git rev-parse --git-common-dir) + if [ "${git_dir}" != "${WORKSPACE}/.git" ]; then + EXTRA_MOUNTS=( "${EXTRA_MOUNTS[@]}" -v "${git_dir}:${git_dir}" ) + fi +fi + # By default we cleanup - remove the container once it finish running (--rm) # and share the PID namespace (--pid=host) so the process inside does not have # pid 1 and SIGKILL is propagated to the process inside (jenkins can kill it). ${DOCKER_BINARY} run --rm --pid=host\ -v ${WORKSPACE}:/workspace \ -v ${SCRIPT_DIR}:/docker \ + "${EXTRA_MOUNTS[@]}" \ -w /workspace \ -e "CI_BUILD_HOME=/workspace" \ -e "CI_BUILD_USER=$(id -u -n)" \ diff --git a/tests/lint/check_file_type.py b/tests/lint/check_file_type.py index e3e74ad..08baaf7 100644 --- a/tests/lint/check_file_type.py +++ b/tests/lint/check_file_type.py @@ -190,7 +190,7 @@ def main(): proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out, _) = proc.communicate() - assert proc.returncode == 0 + assert proc.returncode == 0, f'{" ".join(cmd)} errored: {out}' res = out.decode("utf-8") flist = res.split() error_list = [] -- 2.7.4