From 1f81dc61d147190fb0fbaa2c677df7758725b16e Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 27 May 2026 18:09:09 +0300 Subject: [PATCH 1/4] Fix format pre-commit hook --- eng/formatting/format.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eng/formatting/format.sh b/eng/formatting/format.sh index a2197d696f70b0..43245bc75f6f4f 100755 --- a/eng/formatting/format.sh +++ b/eng/formatting/format.sh @@ -1,6 +1,7 @@ #!/bin/sh LC_ALL=C + # Select files to format NATIVE_FILES=$(git diff --cached --name-only --diff-filter=ACM "*.h" "*.hpp" "*.c" "*.cpp" "*.inl" | sed 's| |\\ |g') MANAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" "*.vb" | sed 's| |\\ |g') @@ -9,7 +10,7 @@ exec 1>&2 if [ -n "$NATIVE_FILES" ]; then # Format all selected files - echo "$NATIVE_FILES" | cat | xargs | sed -e 's/ /,/g' | xargs "./artifacts/tools/clang-format" -style=file -i + echo "$NATIVE_FILES" | xargs "./artifacts/tools/clang-format" -style=file -i # Add back the modified files to staging echo "$NATIVE_FILES" | xargs git add @@ -17,7 +18,7 @@ fi if [ -n "$MANAGED_FILES" ]; then # Format all selected files - echo "$MANAGED_FILES" | cat | xargs | sed -e 's/ /,/g' | dotnet format whitespace --include - --folder + echo "$MANAGED_FILES" | ".dotnet/dotnet" format whitespace --include - --folder # Add back the modified files to staging echo "$MANAGED_FILES" | xargs git add From 635ce5337532259d49b45b4d4010073f299b4751 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 27 May 2026 18:17:16 +0300 Subject: [PATCH 2/4] Update code-formatting-tools.md --- docs/coding-guidelines/code-formatting-tools.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/coding-guidelines/code-formatting-tools.md b/docs/coding-guidelines/code-formatting-tools.md index 9a1175cae2e145..ee4c00105f4899 100644 --- a/docs/coding-guidelines/code-formatting-tools.md +++ b/docs/coding-guidelines/code-formatting-tools.md @@ -80,6 +80,10 @@ In the options view, go to `Text Editor > C/C++ > Code Style > Formatting > Gene Git provides a number of hooks to enable running scripts before commit, push, pull, etc. This section describes adding a pre-commit hook to automatically format code before committing to make formatting seamless even when your development environment doesn't support "format-on-save" or similar functionality with the formatting tools this repository uses. +### Git Hooks + +Git provides a number of hooks to enable running scripts before commit, push, pull, etc. This section describes adding a pre-commit hook to automatically format code before committing to make formatting seamless even when your development environment doesn't support "format-on-save" or similar functionality with the formatting tools this repository uses. + #### Auto-format before committing To enable auto-formatting before committing, you can create a `.git/hooks/pre-commit` file in your local `dotnet/runtime` clone and add a call to the script located at `eng/formatting/format.sh` to auto-format your code before committing. Since Git for Windows also installs Git Bash, this script will work for both Windows and non-Windows platforms. @@ -88,6 +92,8 @@ The following code block can be used as the contents of the `pre-commit` file to ```sh #!/bin/sh -./eng/formatting/format.sh +./eng/formatting/format.sh ``` + +Make sure the file is executable (`chmod +x .git/hooks/pre-commit`). If `git config core.hooksPath` points elsewhere, set it with `git config core.hooksPath .git/hooks`. From 0aa84797e167615ef74b5fbfd7675cdc1a8bb0e5 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 27 May 2026 18:18:47 +0300 Subject: [PATCH 3/4] . --- docs/coding-guidelines/code-formatting-tools.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/coding-guidelines/code-formatting-tools.md b/docs/coding-guidelines/code-formatting-tools.md index ee4c00105f4899..d3a412eb769601 100644 --- a/docs/coding-guidelines/code-formatting-tools.md +++ b/docs/coding-guidelines/code-formatting-tools.md @@ -80,10 +80,6 @@ In the options view, go to `Text Editor > C/C++ > Code Style > Formatting > Gene Git provides a number of hooks to enable running scripts before commit, push, pull, etc. This section describes adding a pre-commit hook to automatically format code before committing to make formatting seamless even when your development environment doesn't support "format-on-save" or similar functionality with the formatting tools this repository uses. -### Git Hooks - -Git provides a number of hooks to enable running scripts before commit, push, pull, etc. This section describes adding a pre-commit hook to automatically format code before committing to make formatting seamless even when your development environment doesn't support "format-on-save" or similar functionality with the formatting tools this repository uses. - #### Auto-format before committing To enable auto-formatting before committing, you can create a `.git/hooks/pre-commit` file in your local `dotnet/runtime` clone and add a call to the script located at `eng/formatting/format.sh` to auto-format your code before committing. Since Git for Windows also installs Git Bash, this script will work for both Windows and non-Windows platforms. From 03873cee273ab1fff9457acf100bbf436fa1cc0c Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:12:17 +0300 Subject: [PATCH 4/4] Apply suggestion from @akoeplinger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- eng/formatting/format.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/formatting/format.sh b/eng/formatting/format.sh index 43245bc75f6f4f..9125e83625ec1a 100755 --- a/eng/formatting/format.sh +++ b/eng/formatting/format.sh @@ -18,7 +18,7 @@ fi if [ -n "$MANAGED_FILES" ]; then # Format all selected files - echo "$MANAGED_FILES" | ".dotnet/dotnet" format whitespace --include - --folder + echo "$MANAGED_FILES" | dotnet format whitespace --include - --folder # Add back the modified files to staging echo "$MANAGED_FILES" | xargs git add