fix: resolve git repo root so revdiff works from subdirectories - #2
Merged
Merged
Conversation
Use git rev-parse --show-toplevel instead of hardcoded "." as the working directory for git commands. Related to #1
There was a problem hiding this comment.
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-toplevelat 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 on lines
+229
to
+230
| out, err := cmd.Output() | ||
| if err != nil { |
There was a problem hiding this comment.
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) | |
| } |
Use git rev-parse --show-toplevel instead of hardcoded "." as the working directory for git commands. Related to #1
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1
Use
git rev-parse --show-toplevelto find the repository root instead of hardcoding.as the working directory. Previously, runningrevdiff HEAD~1from a subdirectory would fail because git diff paths are repo-relative but the working directory was the subdirectory.