|
1 | 1 | #Requires -Version 7.0
|
2 | 2 |
|
3 | | -# This script reformats the entire codebase to make it compliant with our coding guidelines. |
| 3 | +# This script reformats (part of) the codebase to make it compliant with our coding guidelines. |
4 | 4 |
|
5 | | -dotnet tool restore |
| 5 | +param( |
| 6 | + # Git branch name or base commit hash to reformat only the subset of changed files. Omit for all files. |
| 7 | + [string] $revision |
| 8 | +) |
6 | 9 |
|
7 | | -if ($LASTEXITCODE -ne 0) { |
8 | | - throw "Tool restore failed with exit code $LASTEXITCODE" |
| 10 | +function VerifySuccessExitCode { |
| 11 | + if ($LastExitCode -ne 0) { |
| 12 | + throw "Command failed with exit code $LastExitCode." |
| 13 | + } |
9 | 14 | }
|
10 | 15 |
|
| 16 | +dotnet tool restore |
| 17 | +VerifySuccessExitCode |
| 18 | + |
11 | 19 | dotnet restore
|
| 20 | +VerifySuccessExitCode |
12 | 21 |
|
13 | | -if ($LASTEXITCODE-ne0) { |
14 | | - throw"Package restore failed with exit code $LASTEXITCODE" |
15 | | -} |
| 22 | +if ($revision) { |
| 23 | + $headCommitHash= git rev-parse HEAD |
| 24 | + VerifySuccessExitCode |
16 | 25 |
|
17 | | -dotnet regitlint -s JsonApiDotNetCore.sln --print-command --disable-jb-path-hack --jb --profile='\"JADNC Full Cleanup\"' --jb --properties:Configuration=Release --jb --verbosity=WARN |
| 26 | + $baseCommitHash = git rev-parse $revision |
| 27 | + VerifySuccessExitCode |
| 28 | + |
| 29 | + if ($baseCommitHash -eq $headCommitHash) { |
| 30 | + Write-Output "Running code cleanup on staged/unstaged files." |
| 31 | + dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified |
| 32 | + VerifySuccessExitCode |
| 33 | + } |
| 34 | + else { |
| 35 | + Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash, including staged/unstaged files." |
| 36 | + dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash |
| 37 | + VerifySuccessExitCode |
| 38 | + } |
| 39 | +} |
| 40 | +else { |
| 41 | + Write-Output "Running code cleanup on all files." |
| 42 | + dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN |
| 43 | + VerifySuccessExitCode |
| 44 | +} |
0 commit comments