Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/coding-guidelines/code-formatting-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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`.
5 changes: 3 additions & 2 deletions eng/formatting/format.sh
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -9,15 +10,15 @@ 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
Comment thread
akoeplinger marked this conversation as resolved.
echo "$NATIVE_FILES" | xargs "./artifacts/tools/clang-format" -style=file -i

# Add back the modified files to staging
echo "$NATIVE_FILES" | xargs git add
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 format whitespace --include - --folder

# Add back the modified files to staging
echo "$MANAGED_FILES" | xargs git add
Expand Down
Loading