Skip to content

fix: resolve git repo root so revdiff works from subdirectories - #2

Merged
umputun merged 2 commits into
masterfrom
fix/subdirectory-support
Apr 1, 2026
Merged

umputun merged 2 commits into
masterfrom
fix/subdirectory-support

Conversation

@umputun

@umputun umputun commented Apr 1, 2026

Copy link
Copy Markdown
Owner

Fixes #1

Use git rev-parse --show-toplevel to find the repository root instead of hardcoding . as the working directory. Previously, running revdiff HEAD~1 from a subdirectory would fail because git diff paths are repo-relative but the working directory was the subdirectory.

Use git rev-parse --show-toplevel instead of hardcoded "." as the
working directory for git commands. Related to #1
Copilot AI review requested due to automatic review settings April 1, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

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 fixes revdiff failing when invoked from a subdirectory by resolving the Git repository root and using it as the working directory for Git diff operations.

Changes:

  • Resolve repository root via git rev-parse --show-toplevel at startup.
  • Initialize the Git diff renderer with the resolved repo root instead of ".".
  • Add a small helper (gitTopLevel) to encapsulate repo-root discovery.

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

Comment thread cmd/revdiff/main.go
Comment on lines +229 to +230
out, err := cmd.Output()
if err != nil {

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

gitTopLevel wraps cmd.Output() errors directly, which typically loses the useful git error text (e.g. you’ll end up with just exit status 128). Consider mirroring diff.Git.runGit’s handling by detecting *exec.ExitError and including exitErr.Stderr in the returned error message (or using CombinedOutput and formatting stderr on failure).

Suggested change
out, err := cmd.Output()
if err != nil {
out, err := cmd.CombinedOutput()
if err != nil {
msg := strings.TrimSpace(string(out))
if msg != "" {
return "", fmt.Errorf("git rev-parse --show-toplevel: %w: %s", err, msg)
}

Copilot uses AI. Check for mistakes.
Use git rev-parse --show-toplevel instead of hardcoded "." as the
working directory for git commands. Related to #1
@umputun
umputun merged commit c8b7731 into master Apr 1, 2026
2 checks passed
@umputun
umputun deleted the fix/subdirectory-support branch April 1, 2026 20:17
sanchesfree pushed a commit to sanchesfree/revdiff that referenced this pull request Apr 8, 2026
…tun#2)

* fix: resolve git repo root so revdiff works from subdirectories

Use git rev-parse --show-toplevel instead of hardcoded "." as the
working directory for git commands. Related to umputun#1

* fix: resolve git repo root so revdiff works from subdirectories

Use git rev-parse --show-toplevel instead of hardcoded "." as the
working directory for git commands. Related to umputun#1
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.

"revdiff COMMIT" Does not work in subdirectories

2 participants