Fix git diff errors by enforcing default prefixes#18
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that all git diff invocations include the --default-prefix flag to address inconsistencies in diff outputs (fix #17).
- Adds
--default-prefixto both unstaged and staged diffs. - Updates
binary_file_diffto enforce--default-prefixfor initial and cached binary diffs. - Modifies
new_file_diffto apply--default-prefixfor both binary and text “no-index” diffs.
Comments suppressed due to low confidence (2)
src/git.rs:42
- Add unit or integration tests for
unstaged_and_staged_diffsto verify that the--default-prefixflag is included in the underlyinggit diffinvocation and that the resultingDiffis parsed correctly.
let output = call(&["diff", "--default-prefix"], true).or_fail()?;
src/git.rs:112
- [nitpick] There’s no doc comment reflecting the new enforcement of
--default-prefix. Adding a short comment above this function will help future readers understand why this flag is used by default.
pub fn binary_file_diff<P: AsRef<Path>>(path: P) -> orfail::Result<String> {
Comment on lines
+42
to
+46
| let output = call(&["diff", "--default-prefix"], true).or_fail()?; | ||
| Diff::from_str(&output).or_fail() | ||
| }); | ||
| let staged_diff_handle = s.spawn(|| { | ||
| let output = call(&["diff", "--cached"], true).or_fail()?; | ||
| let output = call(&["diff", "--cached", "--default-prefix"], true).or_fail()?; |
There was a problem hiding this comment.
[nitpick] The logic for building git diff argument lists with --default-prefix is duplicated across several functions. Consider extracting a helper that appends this flag to reduce repetition and centralize flag management.
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.
fix #17