feat: add selective line restoration from historical commits
Add a new Tauri command to produce a diff between the working file and a historical commit (get_file_restore_patch) and support a new apply action ("restore-lines") that validates and applies only text-line changes for a single regular file.
Behavior changes and constraints:
- Fetch a filtered reverse diff for a file in a commit so UI can display selectable lines from an older revision.
- Applying "restore-lines" verifies the target is a regular file, rejects binary/metadata patches, and ensures the patch only modifies the selected file.
- Restored lines are applied to the working tree without staging other changes; the index is preserved.
- The operation rejects stale patches or patches targeting the wrong file.
UI wiring:
- Compare dialog gets a "Restore lines…" action for applicable modified files and opens the line-patch dialog in restore mode.
- Line-patch dialog gains a restore mode (restoreCommit) with adjusted UI/rendering to pair removed/added lines, helper text, and dedicated "Restore selected" / "Restore hunk" actions.
- App integration handles fetching the restore patch, applying selected lines, and refreshing views.
Tests:
- Add tests covering correct behavior (preserve unstaged/staged changes and index) and guard cases (stale/wrong-file patches).
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
language?: "en" | "de";
|
||||
onClose: () => void;
|
||||
onRestore?: () => void;
|
||||
onRestoreLines?: () => void;
|
||||
onSelectFile: (file: GitDiffFile) => void;
|
||||
}
|
||||
|
||||
@@ -42,6 +43,7 @@
|
||||
language = "en",
|
||||
onClose = () => {},
|
||||
onRestore = undefined,
|
||||
onRestoreLines = undefined,
|
||||
onSelectFile = () => {},
|
||||
}: Props = $props();
|
||||
|
||||
@@ -242,6 +244,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-header-actions">
|
||||
{#if onRestoreLines && !comparison.to_hash && comparison.files.some(file => file.path === selectedDiffPath && file.status === "modified" && !file.old_path)}
|
||||
<button class="btn-secondary compare-restore" type="button" onclick={onRestoreLines} disabled={isBusy}>
|
||||
<RotateCcw size={15} aria-hidden="true" /><span>{isGerman ? "Zeilen wiederherstellen …" : "Restore lines…"}</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if restoreLabel && onRestore}
|
||||
<button class="btn-secondary compare-restore" type="button" onclick={onRestore} disabled={isBusy} title={restoreLabel}>
|
||||
<RotateCcw size={15} aria-hidden="true" />
|
||||
|
||||
Reference in New Issue
Block a user