From 2aa46e6206422306085975a779353befdd5895e3 Mon Sep 17 00:00:00 2001 From: Smasduq Date: Sun, 30 Aug 2026 11:45:01 +0100 Subject: [PATCH 1/2] Add git work tree detection and validation to CLI scan functionality --- Cargo.lock | 2 +- crates/cli/src/engine/git.rs | 11 +++++++++++ crates/cli/src/scan.rs | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 63a1dc3..e831392 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,7 +203,7 @@ dependencies = [ [[package]] name = "commitor-cli" -version = "0.4.0" +version = "0.5.0" dependencies = [ "anyhow", "chrono", diff --git a/crates/cli/src/engine/git.rs b/crates/cli/src/engine/git.rs index 84a5550..af6973b 100644 --- a/crates/cli/src/engine/git.rs +++ b/crates/cli/src/engine/git.rs @@ -33,6 +33,17 @@ pub fn get_branch_diff(base: &str) -> Result { run_git(&["diff", &format!("{base}...HEAD")]) } +/// True when the current directory is inside a git work tree (bare +/// repos and `.git` directories report `false`). Checks `rev-parse +/// --is-inside-work-tree` because `git diff` outside a repo falls into +/// `--no-index` mode and prints an unrelated usage dump instead of the +/// usual "not a git repository" error. +pub fn is_work_tree() -> bool { + run_git(&["rev-parse", "--is-inside-work-tree"]) + .map(|out| out.trim() == "true") + .unwrap_or(false) +} + /// The full patch text of one diff flavor: staged when `staged`, /// unstaged (working tree) otherwise. pub fn diff_patch(staged: bool) -> Result { diff --git a/crates/cli/src/scan.rs b/crates/cli/src/scan.rs index 0b03985..d395661 100644 --- a/crates/cli/src/scan.rs +++ b/crates/cli/src/scan.rs @@ -17,6 +17,7 @@ use std::process::ExitCode; use anyhow::{bail, Result}; use crate::analysis; +use crate::engine::git; use crate::heuristics::{self, Verdict}; #[derive(Debug, Default)] @@ -46,6 +47,10 @@ fn scan_escalates(verdict: &Verdict, diff_range: bool) -> bool { } pub fn run(flags: ScanFlags) -> Result { + if !git::is_work_tree() { + bail!("this doesn't look like a git repository — run `commitor scan` from inside a git repository"); + } + // Machine-readable output modes suppress the human progress lines. let quiet = flags.json || flags.markdown; From 8cb4cd0fc1bc3ba4572e87f0a06ded955277f24b Mon Sep 17 00:00:00 2001 From: Smasduq Date: Sun, 30 Aug 2026 11:48:46 +0100 Subject: [PATCH 2/2] chore: release v0.5.1 --- CHANGELOG.md | 7 +++++++ Cargo.lock | 2 +- crates/cli/Cargo.toml | 2 +- npm/package.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3736a48..8e33579 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project is in 0.x, minor versions may add, change, or remove functionality freely; 1.0.0 marks a stable command surface. +## [0.5.1] — 2026-08-30 + +### Fixed +- Running `commitor scan` outside a git repository now stops with a clear + "not a git repository" message instead of git's raw diff usage dump. + ## [0.5.0] — 2026-08-29 ### Added @@ -188,6 +194,7 @@ not of the full tool. - `commitor scan` and `commitor commit` — in active development, coming in future 0.x releases. +[0.5.1]: https://github.com/Commitor-AI/commitor/releases/tag/v0.5.1 [0.5.0]: https://github.com/Commitor-AI/commitor/releases/tag/v0.5.0 [0.4.0]: https://github.com/Commitor-AI/commitor/releases/tag/v0.4.0 [0.3.3]: https://github.com/Commitor-AI/commitor/releases/tag/v0.3.3 diff --git a/Cargo.lock b/Cargo.lock index e831392..ae4c87d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,7 +203,7 @@ dependencies = [ [[package]] name = "commitor-cli" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "chrono", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 04a28de..7412035 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "commitor-cli" -version = "0.5.0" +version = "0.5.1" edition = "2021" description = "Catches unrelated changes bundled into commits and splits them cleanly — whole-file or hunk-level, guided by AI analysis" license = "MIT OR Apache-2.0" diff --git a/npm/package.json b/npm/package.json index a20bf21..6f26164 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "commitor-cli", - "version": "0.5.0", + "version": "0.5.1", "description": "Catches unrelated changes bundled into commits and splits them cleanly — whole-file or hunk-level, guided by AI analysis", "bin": { "commitor": "bin/commitor.js"