From 0ef1648a3c1f9125290ca188c035e8e42cc485fe Mon Sep 17 00:00:00 2001 From: "Anaz S. Aji" Date: Thu, 11 Jun 2026 15:49:43 +0700 Subject: [PATCH] fix: friendly error when not in a git repo Detect common git errors (not a git repo, unknown option cached) and return CoraError::NotInGitRepo instead of raw git stderr. Before: 'git command diff --cached failed: error: unknown option cached' After: 'not inside a git repository' 506 tests pass, clippy clean. --- src/git/diff.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/git/diff.rs b/src/git/diff.rs index af90e61c..4678ec0b 100644 --- a/src/git/diff.rs +++ b/src/git/diff.rs @@ -58,6 +58,16 @@ fn git_cmd(args: &[&str]) -> std::result::Result { if !output.status.success() { let stderr = String::from_utf8_lossy(&output.stderr); + let stderr_str = stderr.trim(); + + // Detect common git errors and provide friendly messages + if stderr_str.contains("not a git repository") + || stderr_str.contains("unknown option `cached'") + || stderr_str.contains("Not a git repository") + { + return Err(CoraError::NotInGitRepo); + } + return Err(CoraError::GitCommand { command: args.join(" "), stderr: stderr.to_string(),