From d6b0ab0125fab69efade330c11b99064af8ab981 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 16 Jul 2025 04:45:08 +0200 Subject: [PATCH] Fix Docker volume mount to include parent directories --- formatters/setup-clang-format-docker.sh | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/formatters/setup-clang-format-docker.sh b/formatters/setup-clang-format-docker.sh index c0c57e033..f045aec92 100755 --- a/formatters/setup-clang-format-docker.sh +++ b/formatters/setup-clang-format-docker.sh @@ -11,7 +11,34 @@ docker pull silkeh/clang:18 echo "Creating wrapper script..." cat > /tmp/clang-format-wrapper <<'EOF' #!/bin/bash -exec docker run --rm -i -v "$PWD:$PWD" -w "$PWD" silkeh/clang:18 clang-format "$@" +# Get the absolute path of the file being formatted +args=() +for arg in "$@"; do + if [[ -f "$arg" ]]; then + # Convert to absolute path + args+=("$(realpath "$arg")") + else + args+=("$arg") + fi +done + +# Find the project root (where .github directory is) +current_dir="$PWD" +while [[ "$current_dir" != "/" ]]; do + if [[ -d "$current_dir/.github" ]]; then + project_root="$current_dir" + break + fi + current_dir="$(dirname "$current_dir")" +done + +# If we didn't find project root, use current directory's parent +if [[ -z "$project_root" ]]; then + project_root="$(dirname "$PWD")" +fi + +# Run docker with the project root mounted +exec docker run --rm -i -v "$project_root:$project_root" -w "$PWD" silkeh/clang:18 clang-format "${args[@]}" EOF # Install the wrapper