Files
WSL/tools/hooks/pre-commit.in
Ben Hillis 358ab87d40 Add WSLC (WSL Containers) feature (#40366)
WSLC is a container runtime built on the Windows Subsystem for Linux, enabling Windows applications to create and manage Linux containers through a native Windows API surface.

Key components:
- wslc.exe: CLI for managing containers, images, volumes, and networks
  (build, run, stop, inspect, push/pull from registries)
- wslcsession.exe: Per-user Windows service hosting container lifecycle,
  storage management, and networking
- WSLC SDK: C++ and C# client libraries with NuGet packaging for
  programmatic container management
- Container networking: port forwarding, DNS tunneling, virtio
  networking, and HCN integration
- Storage: VHD-backed volumes, virtiofs file sharing, overlayfs layers
- GPU passthrough and device host proxy support

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: 1wizkid <richard.fricks@hotmail.com>
Co-authored-by: AmirMS <104940545+AmelBawa-msft@users.noreply.github.com>
Co-authored-by: beena352 <beenachauhan@microsoft.com>
Co-authored-by: Blue <OneBlue@users.noreply.github.com>
Co-authored-by: Craig Loewen <crloewen@microsoft.com>
Co-authored-by: Darshak Bhatti <47045043+dabhattimsft@users.noreply.github.com>
Co-authored-by: David Bennett <dbenne@microsoft.com>
Co-authored-by: Feng Wang <wang6922@outlook.com>
Co-authored-by: Flor Chacon <14323496+florelis@users.noreply.github.com>
Co-authored-by: John Stephens <johnstep@microsoft.com>
Co-authored-by: JohnMcPMS <johnmcp@microsoft.com>
Co-authored-by: Kevin Vega <40717198+kvega005@users.noreply.github.com>
Co-authored-by: Pooja Trivedi <poojatrivedi@gmail.com>
Co-authored-by: ramesh-ramn <raman.ramesh@gmail.com>
Co-authored-by: Richard Fricks <richfr@microsoft.com>
Co-authored-by: yao-msft <50888816+yao-msft@users.noreply.github.com>
2026-04-30 13:34:43 -07:00

58 lines
1.9 KiB
Bash

#!/bin/sh
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
#
# Pre-commit hook: validates clang-format on staged C/C++ files.
# Generated by CMake from tools/hooks/pre-commit.in
# Install with: tools\SetupClangFormat.bat
#
# Mode: @WSL_PRE_COMMIT_MODE@ (set WSL_PRE_COMMIT_MODE in UserConfig.cmake)
# warn - report formatting issues without blocking the commit (default)
# error - block the commit when formatting issues are found
# fix - automatically fix formatting and re-stage files
MODE="@WSL_PRE_COMMIT_MODE@"
REPO_ROOT="$(git rev-parse --show-toplevel)"
CLANG_FORMAT="@LLVM_INSTALL_DIR@/clang-format.exe"
# --- Collect staged C/C++ source files ---
STAGED=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp|cxx|h|hpp|hxx)$')
if [ -z "$STAGED" ]; then
exit 0
fi
# --- Verify clang-format is available ---
if [ ! -f "$CLANG_FORMAT" ]; then
echo "[pre-commit] clang-format not found, skipping. Run 'cmake .' to set up."
exit 0
fi
# --- fix mode: format in-place and re-stage ---
if [ "$MODE" = "fix" ]; then
echo "[pre-commit] Fixing formatting..."
echo "$STAGED" | while IFS= read -r file; do
"$CLANG_FORMAT" --style=file -i "$REPO_ROOT/$file"
git add "$REPO_ROOT/$file"
done
echo "[pre-commit] Formatting applied and files re-staged."
exit 0
fi
# --- warn / error mode: check formatting ---
echo "[pre-commit] Checking formatting (mode: $MODE)..."
FILES=$(echo "$STAGED" | sed "s|^|$REPO_ROOT/|")
echo "$FILES" | xargs "$CLANG_FORMAT" --style=file -Werror --dry-run 2>&1
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo ""
echo "[pre-commit] Formatting errors found. Run to fix:"
echo " powershell FormatSource.ps1 -Staged \$true"
if [ "$MODE" = "error" ]; then
exit 1
fi
echo "[pre-commit] Continuing commit (mode: warn)."
else
echo "[pre-commit] All checks passed."
fi