Skip to content

Fix git diff errors by enforcing default prefixes#18

Merged
sile merged 1 commit intosile:mainfrom
zztkm:fix-git-diff-error
Jun 26, 2025
Merged

Fix git diff errors by enforcing default prefixes#18
sile merged 1 commit intosile:mainfrom
zztkm:fix-git-diff-error

Conversation

@zztkm
Copy link
Copy Markdown
Contributor

@zztkm zztkm commented Jun 26, 2025

fix #17

@sile sile requested a review from Copilot June 26, 2025 01:38
Copy link
Copy Markdown
Contributor

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 ensures that all git diff invocations include the --default-prefix flag to address inconsistencies in diff outputs (fix #17).

  • Adds --default-prefix to both unstaged and staged diffs.
  • Updates binary_file_diff to enforce --default-prefix for initial and cached binary diffs.
  • Modifies new_file_diff to apply --default-prefix for 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_diffs to verify that the --default-prefix flag is included in the underlying git diff invocation and that the resulting Diff is 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()?;
Copy link

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

[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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

@sile sile left a comment

Choose a reason for hiding this comment

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

LGTM

@sile sile merged commit 9fa19ad into sile:main Jun 26, 2025
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.

git config で diff.mnemonicPrefix true に設定すると Error: unexpected git diff line が発生する

3 participants