|
9 | 9 | $ErrorActionPreference = 'Stop' |
10 | 10 | Set-StrictMode -Version 2.0 |
11 | 11 | $disableConfigureToolsetImport = $true |
12 | | -$LASTEXITCODE = 0 |
| 12 | +$global:LASTEXITCODE = 0 |
13 | 13 |
|
14 | 14 | try { |
15 | 15 | # `tools.ps1` checks $ci to perform some actions. Since the SDL |
@@ -46,19 +46,26 @@ try { |
46 | 46 | Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git add failed with exit code $LASTEXITCODE." |
47 | 47 | ExitWithExitCode $LASTEXITCODE |
48 | 48 | } |
49 | | - Write-Host "git -c user.email=`"[email protected]`" -c user.name=`"Dotnet Bot`" commit -m `"$PushReason for $Repository/$BranchName`"" |
50 | | - git -c user.email ="[email protected]" -c user.name ="Dotnet Bot" commit -m "$PushReason for $Repository/$BranchName" |
| 49 | + # check if there are any staged changes (0 = no changes, 1 = changes) |
| 50 | + # if we don't do this and there's nothing to commit `git commit` will return |
| 51 | + # exit code 1 and we will fail |
| 52 | + Write-Host "git diff --cached --exit-code" |
| 53 | + git diff --cached --exit-code |
| 54 | + Write-Host "git diff exit code: $LASTEXITCODE" |
51 | 55 | if ($LASTEXITCODE -ne 0) { |
52 | | - Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git commit failed with exit code $LASTEXITCODE." |
53 | | - ExitWithExitCode $LASTEXITCODE |
| 56 | + Write-Host "git -c user.email=`"[email protected]`" -c user.name=`"Dotnet Bot`" commit -m `"$PushReason for $Repository/$BranchName`"" |
| 57 | + git -c user.email ="[email protected]" -c user.name ="Dotnet Bot" commit -m "$PushReason for $Repository/$BranchName" |
| 58 | + if ($LASTEXITCODE -ne 0) { |
| 59 | + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git commit failed with exit code $LASTEXITCODE." |
| 60 | + ExitWithExitCode $LASTEXITCODE |
| 61 | + } |
| 62 | + Write-Host 'git push' |
| 63 | + git push |
| 64 | + if ($LASTEXITCODE -ne 0) { |
| 65 | + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git push failed with exit code $LASTEXITCODE." |
| 66 | + ExitWithExitCode $LASTEXITCODE |
| 67 | + } |
54 | 68 | } |
55 | | - Write-Host 'git push' |
56 | | - git push |
57 | | - if ($LASTEXITCODE -ne 0) { |
58 | | - Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git push failed with exit code $LASTEXITCODE." |
59 | | - ExitWithExitCode $LASTEXITCODE |
60 | | - } |
61 | | - |
62 | 69 | # Return to the original directory |
63 | 70 | Pop-Location |
64 | 71 | } |
|
0 commit comments