Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"name": "revdiff",
"source": "./",
"description": "Review git diffs with inline annotations in a TUI overlay",
"version": "0.2.1",
"version": "0.2.2",
"author": {
"name": "umputun"
}
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "revdiff",
"version": "0.2.1",
"version": "0.2.2",
"description": "Review git diffs with inline annotations in a TUI overlay",
"author": {
"name": "umputun",
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/skills/revdiff/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The script outputs structured fields:
Run the launcher script:

```bash
${CLAUDE_PLUGIN_ROOT}/.claude-plugin/skills/revdiff/scripts/launch-revdiff.sh [ref] [--staged]
${CLAUDE_PLUGIN_ROOT}/.claude-plugin/skills/revdiff/scripts/launch-revdiff.sh [ref] [--staged] [--only=file1 --only=file2]
```

The script:
Expand Down
1 change: 1 addition & 0 deletions .claude-plugin/skills/revdiff/references/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Then uncomment and edit the values you want to change.
| `--wrap` | `REVDIFF_WRAP` | Enable line wrapping in diff view | `false` |
| `--no-confirm-discard` | `REVDIFF_NO_CONFIRM_DISCARD` | Skip confirmation when discarding annotations with Q | `false` |
| `--chroma-style` | `REVDIFF_CHROMA_STYLE` | Chroma color theme for syntax highlighting | `catppuccin-macchiato` |
| `-F`, `--only` | | Show only matching files (may be repeated, matches by path or suffix) | |
| `-o`, `--output` | `REVDIFF_OUTPUT` | Write annotations to file instead of stdout | |
| `--config` | `REVDIFF_CONFIG` | Path to config file | `~/.config/revdiff/config` |
| `--dump-config` | | Print default config to stdout and exit | |
Expand Down
2 changes: 2 additions & 0 deletions .claude-plugin/skills/revdiff/references/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ revdiff # review uncommitted changes
revdiff main # review changes against a branch
revdiff --staged # review staged changes
revdiff HEAD~1 # review last commit
revdiff --only=model.go # review only files matching model.go
revdiff --only=ui/model.go --only=README.md # review specific files
```

## Single-File Mode
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/skills/revdiff/scripts/launch-revdiff.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# launch revdiff in a terminal overlay (tmux/kitty/wezterm) and capture annotations.
# usage: launch-revdiff.sh [ref] [--staged]
# usage: launch-revdiff.sh [ref] [--staged] [--only=file1 ...]
# output: annotation text from revdiff stdout (empty if no annotations)

set -euo pipefail
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ revdiff [OPTIONS] [ref]
| `--wrap` | Enable line wrapping in diff view, env: `REVDIFF_WRAP` | `false` |
| `--no-confirm-discard` | Skip confirmation when discarding annotations with Q, env: `REVDIFF_NO_CONFIRM_DISCARD` | `false` |
| `--chroma-style` | Chroma color theme for syntax highlighting, env: `REVDIFF_CHROMA_STYLE` | `catppuccin-macchiato` |
| `-F`, `--only` | Show only matching files by exact path or suffix, may be repeated (e.g. `--only=model.go`) | |
| `-o`, `--output` | Write annotations to file instead of stdout, env: `REVDIFF_OUTPUT` | |
| `--config` | Path to config file, env: `REVDIFF_CONFIG` | `~/.config/revdiff/config` |
| `--dump-config` | Print default config to stdout and exit | |
Expand Down Expand Up @@ -216,6 +217,9 @@ revdiff --staged

# review last commit
revdiff HEAD~1

# review only specific files
revdiff --only=model.go --only=README.md
```

### Key Bindings
Expand Down
4 changes: 3 additions & 1 deletion cmd/revdiff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type options struct {
NoConfirmDiscard bool `long:"no-confirm-discard" ini-name:"no-confirm-discard" env:"REVDIFF_NO_CONFIRM_DISCARD" description:"skip confirmation prompt when discarding annotations with Q"`
Wrap bool `long:"wrap" ini-name:"wrap" env:"REVDIFF_WRAP" description:"enable line wrapping in diff view"`
ChromaStyle string `long:"chroma-style" ini-name:"chroma-style" env:"REVDIFF_CHROMA_STYLE" default:"catppuccin-macchiato" description:"chroma style for syntax highlighting"`
Output string `long:"output" short:"o" env:"REVDIFF_OUTPUT" no-ini:"true" description:"write annotations to file instead of stdout"`
Only []string `long:"only" short:"F" no-ini:"true" description:"show only these files (may be repeated)"`
Output string `long:"output" short:"o" env:"REVDIFF_OUTPUT" no-ini:"true" description:"write annotations to file instead of stdout"`
Config string `long:"config" env:"REVDIFF_CONFIG" no-ini:"true" description:"path to config file"`
DumpConfig bool `long:"dump-config" no-ini:"true" description:"print default config to stdout and exit"`
Version bool `short:"V" long:"version" no-ini:"true" description:"show version info"`
Expand Down Expand Up @@ -185,6 +186,7 @@ func run(opts options) error {
Ref: opts.Ref.Ref,
Staged: opts.Staged,
TreeWidthRatio: opts.TreeWidth,
Only: opts.Only,
Colors: ui.Colors{
Accent: opts.Colors.Accent,
Border: opts.Colors.Border,
Expand Down
32 changes: 29 additions & 3 deletions ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Model struct {

ref string
staged bool
only []string // filter to show only matching files
noStatusBar bool
focus pane
width int
Expand Down Expand Up @@ -115,7 +116,8 @@ type ModelConfig struct {
NoColors bool // disable all colors including syntax highlighting
NoStatusBar bool // hide the status bar
NoConfirmDiscard bool // skip confirmation prompt when discarding annotations
Wrap bool // enable line wrapping
Wrap bool // enable line wrapping
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModelConfig.Wrap has extra spacing before the comment (bool // ...), which is inconsistent with gofmt output in the rest of the file. Running gofmt (or adjusting the spacing) will keep the struct formatting consistent.

Suggested change
Wrap bool // enable line wrapping
Wrap bool // enable line wrapping

Copilot uses AI. Check for mistakes.
Only []string // show only these files (match by exact path or path suffix)
Colors Colors
}

Expand All @@ -138,6 +140,7 @@ func NewModel(renderer Renderer, store *annotation.Store, highlighter SyntaxHigh
highlighter: highlighter,
ref: cfg.Ref,
staged: cfg.Staged,
only: cfg.Only,
noStatusBar: cfg.NoStatusBar,
noConfirmDiscard: cfg.NoConfirmDiscard,
wrapMode: cfg.Wrap,
Expand Down Expand Up @@ -437,13 +440,36 @@ func (m Model) handleResize(msg tea.WindowSizeMsg) (tea.Model, tea.Cmd) {
return m, nil
}

// filterOnly returns only files matching the --only patterns, or all files if no filter is set.
// matches by exact path or path suffix (e.g. "model.go" matches "ui/model.go").
func (m Model) filterOnly(files []string) []string {
if len(m.only) == 0 {
return files
}
var filtered []string
for _, f := range files {
for _, pattern := range m.only {
if f == pattern || strings.HasSuffix(f, "/"+pattern) {
filtered = append(filtered, f)
break
}
}
}
return filtered
}

func (m Model) handleFilesLoaded(msg filesLoadedMsg) (tea.Model, tea.Cmd) {
if msg.err != nil {
m.viewport.SetContent(fmt.Sprintf("error loading files: %v", msg.err))
return m, nil
}
m.tree = newFileTree(msg.files)
m.singleFile = len(msg.files) == 1
files := m.filterOnly(msg.files)
if len(files) == 0 && len(m.only) > 0 {
m.viewport.SetContent("no files match --only filter")
return m, nil
Comment on lines +466 to +469
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new --only no-match behavior ("no files match --only filter") isn’t covered by tests. Adding a test that sets m.only, sends a filesLoadedMsg with non-matching files, and asserts viewport content + no auto-select cmd would prevent regressions.

Copilot uses AI. Check for mistakes.
}
m.tree = newFileTree(files)
m.singleFile = len(files) == 1
if m.singleFile {
m.focus = paneDiff
m.treeWidth = 0
Expand Down
51 changes: 51 additions & 0 deletions ui/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
Expand Down Expand Up @@ -5162,6 +5163,56 @@ func TestModel_DiffContentWidthSingleFile(t *testing.T) {
})
}

func TestModel_FilterOnly(t *testing.T) {
t.Run("no filter returns all files", func(t *testing.T) {
m := testModel(nil, nil)
files := []string{"ui/model.go", "diff/diff.go", "README.md"}
assert.Equal(t, files, m.filterOnly(files))
})

t.Run("exact path match", func(t *testing.T) {
m := testModel(nil, nil)
m.only = []string{"ui/model.go"}
files := []string{"ui/model.go", "diff/diff.go", "README.md"}
assert.Equal(t, []string{"ui/model.go"}, m.filterOnly(files))
})

t.Run("suffix match", func(t *testing.T) {
m := testModel(nil, nil)
m.only = []string{"model.go"}
files := []string{"ui/model.go", "diff/diff.go", "README.md"}
assert.Equal(t, []string{"ui/model.go"}, m.filterOnly(files))
})

t.Run("multiple patterns", func(t *testing.T) {
m := testModel(nil, nil)
m.only = []string{"model.go", "README.md"}
files := []string{"ui/model.go", "diff/diff.go", "README.md"}
assert.Equal(t, []string{"ui/model.go", "README.md"}, m.filterOnly(files))
})

t.Run("no matches returns empty", func(t *testing.T) {
m := testModel(nil, nil)
m.only = []string{"nonexistent.go"}
files := []string{"ui/model.go", "diff/diff.go"}
assert.Empty(t, m.filterOnly(files))
})
}

func TestModel_FilterOnlyNoMatchShowsMessage(t *testing.T) {
m := testModel(nil, nil)
m.only = []string{"nonexistent.go"}
m.ready = true
m.width = 80
m.height = 24
m.viewport = viewport.New(76, 20)

result, cmd := m.Update(filesLoadedMsg{files: []string{"ui/model.go", "diff/diff.go"}})
model := result.(Model)
assert.Nil(t, cmd, "should not trigger file load when no files match")
assert.Contains(t, model.viewport.View(), "no files match --only filter")
}

func TestModel_SingleFileKeysNoOp(t *testing.T) {
lines := []diff.DiffLine{
{NewNum: 1, Content: "line one", ChangeType: diff.ChangeContext},
Expand Down
Loading