Skip to content

Add --all-files and --exclude modes#19

Merged
umputun merged 7 commits intomasterfrom
all-files-mode
Apr 5, 2026
Merged

Add --all-files and --exclude modes#19
umputun merged 7 commits intomasterfrom
all-files-mode

Conversation

@umputun
Copy link
Copy Markdown
Owner

@umputun umputun commented Apr 5, 2026

Summary

  • --all-files (-A) flag turns revdiff into a general-purpose code browser using git ls-files for file discovery
  • --exclude (-X) flag filters files by path prefix, works with both --all-files and regular diff modes
  • DirectoryReader lists all git-tracked files; ExcludeFilter wraps any renderer for prefix-based exclusion
  • Handles edge cases: deleted files, broken symlinks, binary files, non-regular files, lines exceeding 1MB
  • Mutually exclusive with --staged and --only; validated at CLI level
  • Plugin skill updated with all-files mode triggers and usage

Changes

  • diff/directory.goDirectoryReader using git ls-files, skips deleted files via os.Lstat
  • diff/exclude.goExcludeFilter wrapper with prefix matching
  • diff/fallback.goreadFileAsContext now detects binary files, broken symlinks, non-regular files
  • cmd/revdiff/main.go — CLI flags, validation, renderer selection in makeRenderer()
  • README.md — documents --all-files and --exclude with examples
  • .claude-plugin/skills/revdiff/SKILL.md — all-files mode activation and usage

Copilot AI review requested due to automatic review settings April 5, 2026 08:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an “all-files” browsing mode to revdiff (turning it into a general-purpose code browser over git-tracked files) and introduces prefix-based file exclusion that works across both diff and all-files modes.

Changes:

  • Add --all-files (-A) to list files via git ls-files and render them as context-only (DirectoryReader).
  • Add --exclude (-X) to filter file lists via a renderer wrapper (ExcludeFilter), with config/env support.
  • Harden context-file reading (readFileAsContext) for binary files, broken symlinks, non-regular files, and overly long lines; update CLI/docs/plugin references and tests.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Documents --all-files / --exclude behavior and examples.
docs/plans/completed/2026-04-05-all-files-mode.md Marks implementation plan tasks completed.
diff/fallback.go Adds safer context reading (binary/non-regular/broken symlink/too-long line handling).
diff/fallback_test.go Adds test coverage for new readFileAsContext edge cases.
diff/exclude.go Introduces ExcludeFilter renderer wrapper for prefix filtering.
diff/exclude_test.go Adds unit tests for prefix matching and filtering behavior.
diff/directory.go Adds DirectoryReader for git ls-files-backed discovery.
diff/directory_test.go Adds integration-style tests for listing and reading tracked files.
cmd/revdiff/main.go Wires new CLI flags, validation, renderer selection, and dumpConfig writer generalization.
cmd/revdiff/main_test.go Adds parse/renderer wiring tests for --all-files and --exclude.
CLAUDE.md Updates architecture notes for new renderers and flags.
.claude-plugin/skills/revdiff/SKILL.md Updates skill triggers/argument handling for all-files mode.
.claude-plugin/skills/revdiff/references/usage.md Adds usage docs for all-files and exclude.
.claude-plugin/skills/revdiff/references/config.md Documents new flags and env var behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

diff/exclude.go Outdated
Comment on lines +23 to +26
// normalize prefixes: strip trailing slashes so "vendor/" and "vendor" both work
normalized := make([]string, len(prefixes))
for i, p := range prefixes {
normalized[i] = strings.TrimRight(p, "/")
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

--exclude prefixes are only normalized for trailing "/", but not trimmed for whitespace or empty values. This makes common env/config inputs like REVDIFF_EXCLUDE="vendor, mocks" (note space) fail to match, and a trailing comma produce a useless empty prefix. Consider applying strings.TrimSpace to each prefix and skipping empty results during normalization.

Suggested change
// normalize prefixes: strip trailing slashes so "vendor/" and "vendor" both work
normalized := make([]string, len(prefixes))
for i, p := range prefixes {
normalized[i] = strings.TrimRight(p, "/")
// normalize prefixes: trim whitespace, strip trailing slashes so "vendor/" and "vendor" both work,
// and skip empty values from env/config inputs like trailing commas.
normalized := make([]string, 0, len(prefixes))
for _, p := range prefixes {
p = strings.TrimSpace(p)
p = strings.TrimRight(p, "/")
if p == "" {
continue
}
normalized = append(normalized, p)

Copilot uses AI. Check for mistakes.
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
return nil, fmt.Errorf("git ls-files: %s", string(exitErr.Stderr))
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

On git ls-files failures, the exit-error path returns string(exitErr.Stderr) without trimming and without a fallback when stderr is empty. Git typically includes a trailing newline in stderr, which can leak into TUI error rendering. Consider using strings.TrimSpace and, if the trimmed stderr is empty, fall back to wrapping the original error so the message is still informative.

Suggested change
return nil, fmt.Errorf("git ls-files: %s", string(exitErr.Stderr))
stderr := strings.TrimSpace(string(exitErr.Stderr))
if stderr != "" {
return nil, fmt.Errorf("git ls-files: %s", stderr)
}

Copilot uses AI. Check for mistakes.
Address Copilot review: TrimSpace exclude prefixes so env var input
like "vendor, mocks" works correctly, skip empty values from trailing
commas. Trim git ls-files stderr to avoid trailing newline in errors.
@umputun umputun merged commit e918539 into master Apr 5, 2026
2 checks passed
@umputun umputun deleted the all-files-mode branch April 5, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants