Add Ignore-whitespace toggle to compare and apply to git diff #69

Merged
Christoph merged 1 commit from feat/diff-ignore-whitespace into main 2026-11-04 10:24:08 +00:00
Owner

This change adds an "Ignore whitespace" option to the Compare dialog, threads that option through the front-end -> Tauri invoke layer into the Rust backend, and applies a corresponding git diff flag when generating diffs.

Summary of changes

  • UI: adds a toggle button in CompareDialog.svelte labelled compare.ignoreWhitespace (stored under localStorage key gitlite.diffIgnoreWhitespace) and a small active style in src/app.css. The button is only rendered when a reload handler is provided and updates the currently visible comparison in-place by reloading the comparison data.
  • Front-end plumbing: src/lib/git.ts compare/diff functions (compareCommits, diffFileAgainstWorkingTree, compareFileToHead, compareFileToParent) now accept an optional ignoreWhitespace boolean and pass it to the Tauri invocations. App.svelte introduces a reloadComparison loader and loadComparison/toggleDiffIgnoreWhitespace helpers to persist the toggle and refresh the displayed comparison.
  • Backend plumbing: Tauri Rust API functions in src-tauri/src/git/compare.rs now accept ignore_whitespace: Option<bool> and insert an appropriate git argument via the new helper whitespace_flag(ignore_whitespace). The helper returns --ignore-all-space when requested, otherwise --no-ext-diff as a neutral placeholder so the argument list remains stable across invocations.
  • Tests: existing tests were updated to include the new parameter where applicable, and a new test compare_commits_can_ignore_indentation_only_changes was added in src-tauri/src/git/tests.rs which creates two commits differing only in tabs vs spaces and asserts the strict vs relaxed diffs.
  • i18n: added localization strings for the toggle and a message shown when a file only has whitespace changes in src/lib/locales/en.ts and de.ts.

Why this matters (evidence-backed)

  • Trigger: when a repository contains changes that only alter indentation (e.g. tabs -> spaces), the new toggle causes the backend to call git with --ignore-all-space, which hides those changes in both the summary (--numstat) and the full patch outputs used by the UI.
  • Before: comparisons always showed indentation-only edits as textual changes.
  • After: when the toggle is enabled, the patch and file statistics are produced with --ignore-all-space, and the UI updates the dialog in-place to reflect that there are no textual changes for files that only differ by whitespace.

Testing

No test execution results were provided.

Recommended checks for reviewers:

  • Run the Rust tests that exercise the compare logic: from the repository root run something like
    cargo test --manifest-path src-tauri/Cargo.toml
    to verify the newly added test compiles and passes locally.
  • Launch the app and open the Compare dialog on diffs that include indentation-only edits. Toggle the new "Ignore whitespace" button and verify that the patch and file stats refresh and that whitespace-only changes are hidden when enabled.

Compatibility, risks and reviewer notes

  • The Tauri command signatures were extended with an optional ignore_whitespace parameter. The front-end now sends this parameter; calls that omit it will behave as before (the helper treats None/false as not ignoring whitespace).
  • Implementation note: the helper whitespace_flag returns "--ignore-all-space" when enabled and "--no-ext-diff" when disabled. --no-ext-diff is used as a neutral placeholder so the injected argument spot remains present in the git argument lists. This results in some command arrays containing two occurrences of --no-ext-diff (one original, plus the placeholder) in the non-ignore case — please verify that this is acceptable and harmless for all git invocations in this file.
  • The UI persists the toggle in localStorage under gitlite.diffIgnoreWhitespace. If localStorage is unavailable the code swallows storage errors.

Files/areas to review closely

  • src-tauri/src/git/compare.rs — ensure the inserted argument in each git invocation is correct for that invocation context.
  • src/lib/components/CompareDialog.svelte and src/App.svelte — verify the reload logic (reloadComparison) correctly captures the active comparison call and that selected file highlighting is preserved after reload.
  • The new test compare_commits_can_ignore_indentation_only_changes in src-tauri/src/git/tests.rs — confirm the test covers the intended behavior and is stable across platforms.

If you want, I can highlight the exact hunks that add the toggle and the helper or prepare a short demo script to exercise the new UI flow.

This change adds an "Ignore whitespace" option to the Compare dialog, threads that option through the front-end -> Tauri invoke layer into the Rust backend, and applies a corresponding git diff flag when generating diffs. Summary of changes - UI: adds a toggle button in `CompareDialog.svelte` labelled `compare.ignoreWhitespace` (stored under localStorage key `gitlite.diffIgnoreWhitespace`) and a small `active` style in `src/app.css`. The button is only rendered when a reload handler is provided and updates the currently visible comparison in-place by reloading the comparison data. - Front-end plumbing: `src/lib/git.ts` compare/diff functions (`compareCommits`, `diffFileAgainstWorkingTree`, `compareFileToHead`, `compareFileToParent`) now accept an optional `ignoreWhitespace` boolean and pass it to the Tauri invocations. `App.svelte` introduces a `reloadComparison` loader and `loadComparison`/`toggleDiffIgnoreWhitespace` helpers to persist the toggle and refresh the displayed comparison. - Backend plumbing: Tauri Rust API functions in `src-tauri/src/git/compare.rs` now accept `ignore_whitespace: Option<bool>` and insert an appropriate git argument via the new helper `whitespace_flag(ignore_whitespace)`. The helper returns `--ignore-all-space` when requested, otherwise `--no-ext-diff` as a neutral placeholder so the argument list remains stable across invocations. - Tests: existing tests were updated to include the new parameter where applicable, and a new test `compare_commits_can_ignore_indentation_only_changes` was added in `src-tauri/src/git/tests.rs` which creates two commits differing only in tabs vs spaces and asserts the strict vs relaxed diffs. - i18n: added localization strings for the toggle and a message shown when a file only has whitespace changes in `src/lib/locales/en.ts` and `de.ts`. Why this matters (evidence-backed) - Trigger: when a repository contains changes that only alter indentation (e.g. tabs -> spaces), the new toggle causes the backend to call git with `--ignore-all-space`, which hides those changes in both the summary (`--numstat`) and the full patch outputs used by the UI. - Before: comparisons always showed indentation-only edits as textual changes. - After: when the toggle is enabled, the patch and file statistics are produced with `--ignore-all-space`, and the UI updates the dialog in-place to reflect that there are no textual changes for files that only differ by whitespace. Testing No test execution results were provided. Recommended checks for reviewers: - Run the Rust tests that exercise the compare logic: from the repository root run something like cargo test --manifest-path src-tauri/Cargo.toml to verify the newly added test compiles and passes locally. - Launch the app and open the Compare dialog on diffs that include indentation-only edits. Toggle the new "Ignore whitespace" button and verify that the patch and file stats refresh and that whitespace-only changes are hidden when enabled. Compatibility, risks and reviewer notes - The Tauri command signatures were extended with an optional `ignore_whitespace` parameter. The front-end now sends this parameter; calls that omit it will behave as before (the helper treats `None`/`false` as not ignoring whitespace). - Implementation note: the helper `whitespace_flag` returns `"--ignore-all-space"` when enabled and `"--no-ext-diff"` when disabled. `--no-ext-diff` is used as a neutral placeholder so the injected argument spot remains present in the git argument lists. This results in some command arrays containing two occurrences of `--no-ext-diff` (one original, plus the placeholder) in the non-ignore case — please verify that this is acceptable and harmless for all git invocations in this file. - The UI persists the toggle in `localStorage` under `gitlite.diffIgnoreWhitespace`. If localStorage is unavailable the code swallows storage errors. Files/areas to review closely - `src-tauri/src/git/compare.rs` — ensure the inserted argument in each git invocation is correct for that invocation context. - `src/lib/components/CompareDialog.svelte` and `src/App.svelte` — verify the reload logic (`reloadComparison`) correctly captures the active comparison call and that selected file highlighting is preserved after reload. - The new test `compare_commits_can_ignore_indentation_only_changes` in `src-tauri/src/git/tests.rs` — confirm the test covers the intended behavior and is stable across platforms. If you want, I can highlight the exact hunks that add the toggle and the helper or prepare a short demo script to exercise the new UI flow.
Comparisons can now hide indentation-only differences such as tabs
converted to spaces. The compare commands accept an optional
ignore_whitespace flag that passes --ignore-all-space to git diff; the
dialog toggle is persisted and reloads the open comparison in place.
Line staging/restoring stays exact so patches still apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.