Skip to content

Commit bb4c7c5

Browse files
committed
✨ Add support for branch comparison reviews
Add ability to review code changes between two branches. - Update CLI to accept `--from` and `--to` flags for branch comparison. - Update `review` command to call service function `generate_review_for_branch_diff()` when `--from` and `--to` options are given. - Update GitRepo methods to extract and format branch diff info. - Update review tests to validate CLI branch parameters and tool execution. - Update mcp tool to handle branch comparisons. - Add flag validation to prevent usage of incompatible flags.
1 parent 017823a commit bb4c7c5

File tree

13 files changed

+1448
-131
lines changed

13 files changed

+1448
-131
lines changed

README.md

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,57 @@ Example:
302302
git-iris review -i "Focus on security" --preset security --include-unstaged
303303
```
304304

305+
For more comprehensive reviews, you can also:
306+
307+
- **Review unstaged changes**: Include unstaged changes in the review
308+
```bash
309+
git-iris review --include-unstaged
310+
```
311+
312+
- **Review a specific commit**: Analyze a particular commit
313+
```bash
314+
git-iris review --commit abc123
315+
```
316+
317+
- **Review branch differences**: Compare entire branches (perfect for PR reviews)
318+
```bash
319+
git-iris review --from main --to feature-branch
320+
```
321+
322+
The branch comparison feature is particularly powerful for reviewing pull requests, as it analyzes all changes between two branches, giving you a comprehensive view of the entire feature or fix.
323+
324+
**Smart Branch Comparison**: Git-Iris uses merge-base comparison to ensure you only see changes relevant to the feature branch, not unrelated changes that happened in the base branch after the feature branch was created. This provides accurate PR reviews even when the base branch has moved forward.
325+
326+
Example usage:
327+
328+
```bash
329+
# Compare feature branch to main (explicit)
330+
git-iris review --from main --to feature-branch
331+
332+
# Compare feature branch to main (using default)
333+
git-iris review --to feature-branch # --from defaults to 'main'
334+
```
335+
336+
The review includes:
337+
338+
- A summary of the changes
339+
- Code quality assessment
340+
- Suggestions for improvement
341+
- Identified issues
342+
- Positive aspects of your code
343+
- Analysis across 11 dimensions of code quality:
344+
- Complexity - Identifies unnecessary complexity in algorithms and control flow
345+
- Abstraction - Assesses appropriateness of abstractions and design patterns
346+
- Unintended Deletion - Detects critical functionality removed without replacement
347+
- Hallucinated Components - Flags references to non-existent functions or APIs
348+
- Style Inconsistencies - Highlights deviations from project coding standards
349+
- Security Vulnerabilities - Identifies potential security issues
350+
- Performance Issues - Spots inefficient algorithms or resource usage
351+
- Code Duplication - Detects repeated logic or copy-pasted code
352+
- Error Handling - Evaluates completeness of error recovery strategies
353+
- Test Coverage - Analyzes test coverage gaps or brittle tests
354+
- Best Practices - Checks adherence to language-specific conventions and design guidelines
355+
305356
### Generate Changelogs
306357

307358
Create a detailed changelog between Git references:
@@ -476,34 +527,6 @@ The interactive CLI allows you to refine and perfect your commit messages:
476527
- Press Enter to commit
477528
- Press Esc to cancel
478529

479-
### Getting an AI Code Review
480-
481-
Git-Iris can analyze your staged changes and provide a detailed code review:
482-
483-
```bash
484-
git-iris review
485-
```
486-
487-
The review includes:
488-
489-
- A summary of the changes
490-
- Code quality assessment
491-
- Suggestions for improvement
492-
- Identified issues
493-
- Positive aspects of your code
494-
- Analysis across 11 dimensions of code quality:
495-
- Complexity - Identifies unnecessary complexity in algorithms and control flow
496-
- Abstraction - Assesses appropriateness of abstractions and design patterns
497-
- Unintended Deletion - Detects critical functionality removed without replacement
498-
- Hallucinated Components - Flags references to non-existent functions or APIs
499-
- Style Inconsistencies - Highlights deviations from project coding standards
500-
- Security Vulnerabilities - Identifies potential security issues
501-
- Performance Issues - Spots inefficient algorithms or resource usage
502-
- Code Duplication - Detects repeated logic or copy-pasted code
503-
- Error Handling - Evaluates completeness of error recovery strategies
504-
- Test Coverage - Analyzes test coverage gaps or brittle tests
505-
- Best Practices - Checks adherence to language-specific conventions and design guidelines
506-
507530
## 🎛️ Custom Instructions and Presets
508531

509532
Git-Iris offers two powerful ways to guide the AI in generating commit messages: custom instructions and presets.

git-iris.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ Include unstaged changes in the review
9090
.TP
9191
.BR \-\-commit =\fICOMMIT_ID\fR
9292
Review a specific commit by ID (hash, branch, or reference)
93+
.TP
94+
.BR \-\-from =\fIBRANCH\fR
95+
Starting branch for comparison (defaults to 'main'). Used with --to for branch comparison reviews. Ideal for reviewing entire PRs or feature branches.
96+
.TP
97+
.BR \-\-to =\fIBRANCH\fR
98+
Target branch for comparison (e.g., 'feature-branch', 'pr-branch'). Used with --from for branch comparison reviews. If only --to is specified, --from defaults to 'main'. The changes from --from to --to will be reviewed
9399
.SH "CHANGELOG COMMAND OPTIONS"
94100
.TP
95101
.BR \-\-from =\fIREF\fR

src/changes/prompt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ fn format_metrics_summary(prompt: &mut String, total_metrics: &ChangeMetrics) {
256256

257257
/// Common helper function to format individual change details
258258
fn format_change_details(prompt: &mut String, change: &AnalyzedChange, detail_level: DetailLevel) {
259-
writeln!(prompt, "Commit: {}", change.commit_hash).expect("writing to string should never fail");
259+
writeln!(prompt, "Commit: {}", change.commit_hash)
260+
.expect("writing to string should never fail");
260261
writeln!(prompt, "Author: {}", change.author).expect("writing to string should never fail");
261262
writeln!(prompt, "Message: {}", change.commit_message)
262263
.expect("writing to string should never fail");
263-
writeln!(prompt, "Type: {:?}", change.change_type).expect("writing to string should never fail");
264+
writeln!(prompt, "Type: {:?}", change.change_type)
265+
.expect("writing to string should never fail");
264266
writeln!(prompt, "Breaking Change: {}", change.is_breaking_change)
265267
.expect("writing to string should never fail");
266268
writeln!(

src/changes/releasenotes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ fn format_release_notes_response(
110110
if !response.upgrade_notes.is_empty() {
111111
formatted.push_str(&"## 🔧 Upgrade Notes\n\n".yellow().bold().to_string());
112112
for note in &response.upgrade_notes {
113-
writeln!(formatted, "- {note}")
114-
.expect("writing to string should never fail");
113+
writeln!(formatted, "- {note}").expect("writing to string should never fail");
115114
}
116115
formatted.push('\n');
117116
}

src/cli.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ pub enum Commands {
128128
help = "Review a specific commit by ID (hash, branch, or reference)"
129129
)]
130130
commit: Option<String>,
131+
132+
/// Starting branch for comparison (defaults to 'main')
133+
#[arg(
134+
long,
135+
help = "Starting branch for comparison (defaults to 'main'). Used with --to for branch comparison reviews"
136+
)]
137+
from: Option<String>,
138+
139+
/// Target branch for comparison (e.g., 'feature-branch', 'pr-branch')
140+
#[arg(
141+
long,
142+
help = "Target branch for comparison (e.g., 'feature-branch', 'pr-branch'). Used with --from for branch comparison reviews"
143+
)]
144+
to: Option<String>,
131145
},
132146

133147
/// Generate a changelog
@@ -401,18 +415,30 @@ async fn handle_review(
401415
repository_url: Option<String>,
402416
include_unstaged: bool,
403417
commit: Option<String>,
418+
from: Option<String>,
419+
to: Option<String>,
404420
) -> anyhow::Result<()> {
405421
log_debug!(
406-
"Handling 'review' command with common: {:?}, print: {}, include_unstaged: {}, commit: {:?}",
422+
"Handling 'review' command with common: {:?}, print: {}, include_unstaged: {}, commit: {:?}, from: {:?}, to: {:?}",
407423
common,
408424
print,
409425
include_unstaged,
410-
commit
426+
commit,
427+
from,
428+
to
411429
);
412430
ui::print_version(crate_version!());
413431
ui::print_newline();
414-
commit::review::handle_review_command(common, print, repository_url, include_unstaged, commit)
415-
.await
432+
commit::review::handle_review_command(
433+
common,
434+
print,
435+
repository_url,
436+
include_unstaged,
437+
commit,
438+
from,
439+
to,
440+
)
441+
.await
416442
}
417443

418444
/// Handle the `Changelog` command
@@ -510,7 +536,20 @@ pub async fn handle_command(
510536
print,
511537
include_unstaged,
512538
commit,
513-
} => handle_review(common, print, repository_url, include_unstaged, commit).await,
539+
from,
540+
to,
541+
} => {
542+
handle_review(
543+
common,
544+
print,
545+
repository_url,
546+
include_unstaged,
547+
commit,
548+
from,
549+
to,
550+
)
551+
.await
552+
}
514553
Commands::Changelog {
515554
common,
516555
from,

0 commit comments

Comments
 (0)