Skip to content

Commit 5d051b9

Browse files
committed
Default to git diff when stdin is empty
1 parent fefa094 commit 5d051b9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ git diff | diffscope review
7474
# Review a specific file diff
7575
diffscope review --diff patch.diff
7676

77+
# Run without stdin to review uncommitted changes
78+
diffscope review
79+
7780
# Get enhanced analysis with smart review
7881
git diff | diffscope smart-review
7982
```
@@ -89,6 +92,9 @@ diffscope git uncommitted
8992
# Compare your branch to main
9093
diffscope git branch main
9194

95+
# Compare your branch to the repo default
96+
diffscope git branch
97+
9298
# Get AI-powered commit message suggestions
9399
diffscope git suggest
94100
```

src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use anyhow::Result;
77
use clap::{Parser, Subcommand};
88
use once_cell::sync::Lazy;
99
use regex::Regex;
10+
use std::io::IsTerminal;
1011
use std::path::{Path, PathBuf};
1112
use tracing::info;
1213
use tracing_subscriber::EnvFilter;
@@ -230,6 +231,18 @@ async fn review_command(
230231

231232
let diff_content = if let Some(path) = diff_path {
232233
tokio::fs::read_to_string(path).await?
234+
} else if std::io::stdin().is_terminal() {
235+
if let Ok(git) = core::GitIntegration::new(".") {
236+
let diff = git.get_uncommitted_diff()?;
237+
if diff.is_empty() {
238+
println!("No changes found");
239+
return Ok(());
240+
}
241+
diff
242+
} else {
243+
println!("No diff provided and not in a git repository.");
244+
return Ok(());
245+
}
233246
} else {
234247
use std::io::Read;
235248
let mut buffer = String::new();
@@ -1163,6 +1176,18 @@ async fn smart_review_command(
11631176

11641177
let diff_content = if let Some(path) = diff_path {
11651178
tokio::fs::read_to_string(path).await?
1179+
} else if std::io::stdin().is_terminal() {
1180+
if let Ok(git) = core::GitIntegration::new(".") {
1181+
let diff = git.get_uncommitted_diff()?;
1182+
if diff.is_empty() {
1183+
println!("No changes found");
1184+
return Ok(());
1185+
}
1186+
diff
1187+
} else {
1188+
println!("No diff provided and not in a git repository.");
1189+
return Ok(());
1190+
}
11661191
} else {
11671192
use std::io::Read;
11681193
let mut buffer = String::new();

0 commit comments

Comments
 (0)