From 88324c21c28a7aa919e4fbe36d354631f3306aa4 Mon Sep 17 00:00:00 2001 From: SidneyZhang Date: Mon, 2 Feb 2026 14:57:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=20GPG=20=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E5=A4=B1=E8=B4=A5=E6=97=B6=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/commit.rs | 17 ++++++++++++++++- src/git/commit.rs | 17 ++++++++++++++++- src/git/mod.rs | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/commands/commit.rs b/src/commands/commit.rs index 8c02e38..95e2dc4 100644 --- a/src/commands/commit.rs +++ b/src/commands/commit.rs @@ -350,8 +350,23 @@ impl CommitCommand { .output()?; if !output.status.success() { + let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - bail!("Failed to amend commit: {}", stderr); + + let error_msg = if stderr.is_empty() { + if stdout.is_empty() { + "GPG signing failed. Please check:\n\ + 1. GPG signing key is configured (git config --get user.signingkey)\n\ + 2. GPG agent is running\n\ + 3. You can sign commits manually (try: git commit --amend -S)".to_string() + } else { + stdout.to_string() + } + } else { + stderr.to_string() + }; + + bail!("Failed to amend commit: {}", error_msg); } Ok(()) diff --git a/src/git/commit.rs b/src/git/commit.rs index 53da566..1807025 100644 --- a/src/git/commit.rs +++ b/src/git/commit.rs @@ -174,8 +174,23 @@ impl CommitBuilder { .output()?; if !output.status.success() { + let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - bail!("Failed to amend commit: {}", stderr); + + let error_msg = if stderr.is_empty() { + if stdout.is_empty() { + "GPG signing failed. Please check:\n\ + 1. GPG signing key is configured (git config --get user.signingkey)\n\ + 2. GPG agent is running\n\ + 3. You can sign commits manually (try: git commit --amend -S)".to_string() + } else { + stdout.to_string() + } + } else { + stderr.to_string() + }; + + bail!("Failed to amend commit: {}", error_msg); } Ok(()) diff --git a/src/git/mod.rs b/src/git/mod.rs index 3442b58..de4882e 100644 --- a/src/git/mod.rs +++ b/src/git/mod.rs @@ -374,8 +374,23 @@ impl GitRepo { .output()?; if !output.status.success() { + let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - bail!("Failed to create signed commit: {}", stderr); + + let error_msg = if stderr.is_empty() { + if stdout.is_empty() { + "GPG signing failed. Please check:\n\ + 1. GPG signing key is configured (git config --get user.signingkey)\n\ + 2. GPG agent is running\n\ + 3. You can sign commits manually (try: git commit -S -m 'test')".to_string() + } else { + stdout.to_string() + } + } else { + stderr.to_string() + }; + + bail!("Failed to create signed commit: {}", error_msg); } let head = self.repo.head()?;