From b6124267827749a8e99f42f4dbc6d1f50141190c Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Thu, 8 Sep 2022 10:27:17 +0200 Subject: [PATCH] Add git hook for formating (#2224) --- .git-hooks/pre-commit | 8 ++++++++ README.md | 12 ++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100755 .git-hooks/pre-commit diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit new file mode 100755 index 000000000..bc661efae --- /dev/null +++ b/.git-hooks/pre-commit @@ -0,0 +1,8 @@ +#!/bin/bash + +FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs") +if [ -n "$FILES" ] +then + dotnet format ./bitwarden-server.sln --no-restore --include $FILES + echo "$FILES" | xargs git add +fi diff --git a/README.md b/README.md index eff0f170c..b1a4a9a54 100644 --- a/README.md +++ b/README.md @@ -75,15 +75,11 @@ No grant of any rights in the trademarks, service marks, or logos of Bitwarden i ### Dotnet-format -We recently migrated to using dotnet-format as code formatter. All previous branches will need to updated to avoid large merge conflicts using the following steps: +Consider installing our git pre-commit hook for automatic formatting. -1. Check out your local Branch -2. Run `git merge 61dc65aa598b1f492d2f0222bb7bf0dd15d116f5` -3. Resolve any merge conflicts, commit. -4. Run `dotnet tool run dotnet-format` -5. Commit -6. Run `git merge -Xours 23b0a1f9df25058ab29785ecad9a233113c10889` -7. Push +```bash +git config --local core.hooksPath .git-hooks +``` ### File Scoped Namespaces