Add branch file transfers, merge previews and branch cleanup tools #67

Merged
Christoph merged 15 commits from codex/branch-workflows into main 2026-10-11 20:43:56 +00:00
Owner

This change adds branch-focused workflows and supporting plumbing for selecting and transferring files or parts of files between branches, previewing merges, and cleaning up merged or stale branch refs.

In short: the repository gains new Tauri commands and client-visible flows to take or merge individual files/lines from another branch, preview the effects of merging a branch into the current branch, undo the last file transfer, and review/delete eligible local (and optionally stale remote-tracking) refs.

Key outcomes (evidence from diffs):

  • File/line selection and restore

    • New commands in src-tauri/src/git/branch_files.rs: get_branch_file_changes, take_branch_files, get_branch_file_patch, and apply_branch_file_patch implement selecting files, computing/returning patches for selected lines/hunks, and applying those patches with checks. They validate repository state (expected HEAD and branch), refuse submodules and directory/file transitions, and avoid traversing worktree symlinks before modifying files.
    • The UI-facing behavior is documented in README.md under "Branch workflows": you can right-click another branch and "Take files …", select files or individual lines/hunks, and restore or stage the selected content. Results are left unstaged; index and branch tip are preserved.
    • A node test was added at scripts/line-patch.test.mjs that compiles a selection helper from the Svelte component source and exercises selection of lines beginning with --- and +++ to ensure those lines can be recognized and selected.
  • Three-way file merge workbench for selected file merges

    • src-tauri/src/git/branch_merge.rs exposes merge-related types and functions to produce a common-ancestor three-way merge for a file (base/ours/theirs), return content and executable bits, and drive a conflict workbench-style resolution. The README notes that the same workbench as normal conflict resolution is used for per-file merges.
  • Previewing branch merges

    • README.md documents that "Merge into current" now calculates a preview (affected files, resulting diff, predicted conflicts, and fast-forward availability) before applying; the preview uses committed states and requires Git 2.38+ (as stated in the README). The underlying plumbing is exposed by adding merge_preview to src-tauri/src/git.rs.
  • Branch cleanup assistant

    • src-tauri/src/git/branch_cleanup.rs implements preview_branch_cleanup and apply_branch_cleanup. The preview collects branch candidates (local heads) and optional remote-tracking references, classifies them (merged/unmerged/protected/worktree/base), and returns a plan. apply_branch_cleanup re-checks the plan, verifies selected refs and commit IDs, prevents deleting refs in-use by worktrees, and performs atomic ref deletions via git update-ref --stdin. The code explicitly skips server-side deletes and warns/skips remotes with custom fetch mappings.
  • Persistent per-worktree undo for file transfers

    • Branch file apply paths wrap the actual transfer in with_transfer_undo(...) (module exposed in src-tauri/src/git.rs), preserving the previous contents so the UI can restore the last transfer for the worktree. The README documents the conditions under which the undo is refused (it will not overwrite newer edits, staging changes, or a changed branch/HEAD).
  • Safety checks and constraints

    • The new code performs explicit validations: verifying HEAD and current branch before applying changes, refusing operations when a merge/rebase/cherry-pick is in progress or unresolved conflicts exist, disallowing non-regular files (submodules, directory replacements), and checking parent paths to avoid following symlinks when restoring files. These checks are visible in branch_files.rs, branch_merge.rs and branch_cleanup.rs.

Files changed or added (high level):

  • Added commands and modules: src-tauri/src/git/branch_files.rs, branch_merge.rs, branch_cleanup.rs, transfer_undo and merge_preview are wired into src-tauri/src/git.rs.
  • Documentation: README.md and CHANGELOG.md updated to describe the new branch workflows and features.
  • Tests: scripts/line-patch.test.mjs added to exercise the patch parser/selection logic.

Testing

  • Tests added/changed: scripts/line-patch.test.mjs is a new unit-style test that compiles and exercises the component's patch parsing/selecting logic against a real Git repo.
  • No test execution results were provided.

Recommended checks for reviewers

  • Build and run the Tauri backend: cargo build (or the project's normal Tauri build step) to ensure the new Rust modules compile and are wired correctly.
  • Run the new node test locally: node --test scripts/line-patch.test.mjs (or your project's test command) to exercise the patch selection logic that recognizes ---/+++ lines.
  • Manually exercise the UI flows (or call the added Tauri commands) in a non-critical repo: preview a merge (check fast-forward/conflict prediction), select files and lines from another branch and apply/undo a file transfer, and run the branch cleanup preview then apply on a safe test repo.

Compatibility and migration notes

  • Merge preview requires Git 2.38+ to report predicted fast-forward availability as documented in README.md.
  • The branch cleanup assistant only considers remotes using the conventional refs/heads/*:refs/remotes/<remote>/* fetch mapping; remotes with custom fetch mappings are skipped with a warning (this behavior is implemented in branch_cleanup.rs). Server branches are not deleted by this assistant.
  • The undo record is per-worktree and survives restarts but is replaced by the next transfer; the undo refuses to overwrite newer edits or a changed HEAD/branch (see README and with_transfer_undo usage).

Notes for reviewers

  • Focus review on correctness of path/symlink checks, the expected HEAD/branch verification logic, and the atomic ref deletion flow in apply_branch_cleanup.
  • The new node test verifies the line-selection behavior for ---/+++ markers; no run output was supplied, so please run it locally as part of review.

If you want, I can list the public Tauri command names added and their parameter shapes, or extract the most important functions to test interactively.

This change adds branch-focused workflows and supporting plumbing for selecting and transferring files or parts of files between branches, previewing merges, and cleaning up merged or stale branch refs. In short: the repository gains new Tauri commands and client-visible flows to take or merge individual files/lines from another branch, preview the effects of merging a branch into the current branch, undo the last file transfer, and review/delete eligible local (and optionally stale remote-tracking) refs. Key outcomes (evidence from diffs): - File/line selection and restore - New commands in `src-tauri/src/git/branch_files.rs`: `get_branch_file_changes`, `take_branch_files`, `get_branch_file_patch`, and `apply_branch_file_patch` implement selecting files, computing/returning patches for selected lines/hunks, and applying those patches with checks. They validate repository state (expected HEAD and branch), refuse submodules and directory/file transitions, and avoid traversing worktree symlinks before modifying files. - The UI-facing behavior is documented in `README.md` under "Branch workflows": you can right-click another branch and "Take files …", select files or individual lines/hunks, and restore or stage the selected content. Results are left unstaged; index and branch tip are preserved. - A node test was added at `scripts/line-patch.test.mjs` that compiles a selection helper from the Svelte component source and exercises selection of lines beginning with `---` and `+++` to ensure those lines can be recognized and selected. - Three-way file merge workbench for selected file merges - `src-tauri/src/git/branch_merge.rs` exposes merge-related types and functions to produce a common-ancestor three-way merge for a file (base/ours/theirs), return content and executable bits, and drive a conflict workbench-style resolution. The README notes that the same workbench as normal conflict resolution is used for per-file merges. - Previewing branch merges - README.md documents that "Merge into current" now calculates a preview (affected files, resulting diff, predicted conflicts, and fast-forward availability) before applying; the preview uses committed states and requires Git 2.38+ (as stated in the README). The underlying plumbing is exposed by adding `merge_preview` to `src-tauri/src/git.rs`. - Branch cleanup assistant - `src-tauri/src/git/branch_cleanup.rs` implements `preview_branch_cleanup` and `apply_branch_cleanup`. The preview collects branch candidates (local heads) and optional remote-tracking references, classifies them (merged/unmerged/protected/worktree/base), and returns a plan. `apply_branch_cleanup` re-checks the plan, verifies selected refs and commit IDs, prevents deleting refs in-use by worktrees, and performs atomic ref deletions via `git update-ref --stdin`. The code explicitly skips server-side deletes and warns/skips remotes with custom fetch mappings. - Persistent per-worktree undo for file transfers - Branch file apply paths wrap the actual transfer in `with_transfer_undo(...)` (module exposed in `src-tauri/src/git.rs`), preserving the previous contents so the UI can restore the last transfer for the worktree. The README documents the conditions under which the undo is refused (it will not overwrite newer edits, staging changes, or a changed branch/HEAD). - Safety checks and constraints - The new code performs explicit validations: verifying HEAD and current branch before applying changes, refusing operations when a merge/rebase/cherry-pick is in progress or unresolved conflicts exist, disallowing non-regular files (submodules, directory replacements), and checking parent paths to avoid following symlinks when restoring files. These checks are visible in `branch_files.rs`, `branch_merge.rs` and `branch_cleanup.rs`. Files changed or added (high level): - Added commands and modules: `src-tauri/src/git/branch_files.rs`, `branch_merge.rs`, `branch_cleanup.rs`, `transfer_undo` and `merge_preview` are wired into `src-tauri/src/git.rs`. - Documentation: `README.md` and `CHANGELOG.md` updated to describe the new branch workflows and features. - Tests: `scripts/line-patch.test.mjs` added to exercise the patch parser/selection logic. Testing - Tests added/changed: `scripts/line-patch.test.mjs` is a new unit-style test that compiles and exercises the component's patch parsing/selecting logic against a real Git repo. - No test execution results were provided. Recommended checks for reviewers - Build and run the Tauri backend: `cargo build` (or the project's normal Tauri build step) to ensure the new Rust modules compile and are wired correctly. - Run the new node test locally: `node --test scripts/line-patch.test.mjs` (or your project's test command) to exercise the patch selection logic that recognizes `---`/`+++` lines. - Manually exercise the UI flows (or call the added Tauri commands) in a non-critical repo: preview a merge (check fast-forward/conflict prediction), select files and lines from another branch and apply/undo a file transfer, and run the branch cleanup preview then apply on a safe test repo. Compatibility and migration notes - Merge preview requires Git 2.38+ to report predicted fast-forward availability as documented in `README.md`. - The branch cleanup assistant only considers remotes using the conventional `refs/heads/*:refs/remotes/<remote>/*` fetch mapping; remotes with custom fetch mappings are skipped with a warning (this behavior is implemented in `branch_cleanup.rs`). Server branches are not deleted by this assistant. - The undo record is per-worktree and survives restarts but is replaced by the next transfer; the undo refuses to overwrite newer edits or a changed HEAD/branch (see README and `with_transfer_undo` usage). Notes for reviewers - Focus review on correctness of path/symlink checks, the expected HEAD/branch verification logic, and the atomic ref deletion flow in `apply_branch_cleanup`. - The new node test verifies the line-selection behavior for `---`/`+++` markers; no run output was supplied, so please run it locally as part of review. If you want, I can list the public Tauri command names added and their parameter shapes, or extract the most important functions to test interactively.
Sign in to join this conversation.
No description provided.