From 35b283d63397cfa9ece474d2e6d97697d815ebcc Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Sun, 4 Oct 2026 10:17:52 +0800 Subject: [PATCH] Check Git command exit codes --- src/CLI/RodelCommit/CommitService.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/CLI/RodelCommit/CommitService.cs b/src/CLI/RodelCommit/CommitService.cs index 42a329bd..4fd36bdf 100644 --- a/src/CLI/RodelCommit/CommitService.cs +++ b/src/CLI/RodelCommit/CommitService.cs @@ -521,6 +521,11 @@ private static async Task GenerateCommitAsync(string commitMessage, bool needEdi _ = await commitProcess.StandardOutput.ReadToEndAsync().ConfigureAwait(false); var commitError = await commitProcess.StandardError.ReadToEndAsync().ConfigureAwait(false); await commitProcess.WaitForExitAsync(); + if (commitProcess.ExitCode != 0) + { + throw new InvalidOperationException($"git commit failed with exit code {commitProcess.ExitCode}: {commitError}"); + } + AnsiConsole.MarkupLine("[green]Commit successfully.[/]"); if (!string.IsNullOrEmpty(commitError)) { @@ -550,6 +555,11 @@ private static async Task PushCommitAsync(string commitMessage) _ = await pushProcess.StandardOutput.ReadToEndAsync().ConfigureAwait(false); var pushError = await pushProcess.StandardError.ReadToEndAsync().ConfigureAwait(false); await pushProcess.WaitForExitAsync(); + if (pushProcess.ExitCode != 0) + { + throw new InvalidOperationException($"git push failed with exit code {pushProcess.ExitCode}: {pushError}"); + } + AnsiConsole.MarkupLine("[green]Push successfully.[/]"); if (!string.IsNullOrEmpty(pushError)) {