Flux Labs
|
343a43f028
|
feat: move git operations to Rust via git2 crate (#572)
* feat: move git operations to Rust via git2 crate (#524)
Eliminates ~70 execSync/execFileSync git CLI calls across 15 TypeScript
files by implementing native libgit2 operations in Rust and routing all
consumers through the native-git-bridge.
Rust (native/crates/engine/src/git.rs):
- Added 28 new NAPI functions covering both read and write operations
- Read: git_is_repo, git_has_staged_changes, git_diff_stat,
git_diff_name_status, git_diff_numstat, git_diff_content,
git_log_oneline, git_worktree_list, git_branch_list,
git_branch_list_merged, git_ls_files, git_for_each_ref,
git_conflict_files, git_batch_info
- Write: git_init, git_add_all, git_add_paths, git_reset_paths,
git_commit, git_checkout_branch, git_checkout_theirs,
git_merge_squash, git_merge_abort, git_rebase_abort,
git_reset_hard, git_branch_delete, git_branch_force_reset,
git_rm_cached, git_rm_force, git_worktree_add,
git_worktree_remove, git_worktree_prune, git_revert_commit,
git_revert_abort, git_update_ref
TypeScript (native-git-bridge.ts):
- Added 35 bridge functions with native-first + execSync fallback
- New types: GitDiffStat, GitNameStatus, GitNumstat, GitLogEntry,
GitWorktreeEntry, GitBatchInfo, GitMergeResult
Consumer migrations (15 files):
- worktree-manager.ts: removed local runGit/getMainBranch, all ops native
- auto-worktree.ts: merge, checkout, conflict resolution all native
- git-service.ts: smart staging, commits, snapshots all native
- auto.ts, guided-flow.ts: repo init/bootstrap native
- auto-supervisor.ts: working tree detection native
- git-self-heal.ts: merge/rebase abort, reset all native
- doctor.ts: health checks, branch listing, worktree cleanup native
- commands.ts: branch/snapshot cleanup native
- session-forensics.ts: diff stat queries native
- auto-recovery.ts: merge state reconciliation native
- gitignore.ts, undo.ts, worktree-command.ts: remaining ops native
Kept as execSync (by design):
- git push (credential handling too complex for libgit2)
- native-git-bridge.ts fallbacks (graceful degradation)
- runPreMergeCheck (runs arbitrary user commands)
Closes #524
* fix: restore getMainBranch export from worktree-manager
The agent migration removed getMainBranch from worktree-manager.ts but
worktree-command.ts still imports it. Re-add as a thin wrapper around
nativeDetectMainBranch.
* fix: address PR #572 review feedback — security, correctness, error handling
CRITICAL:
- Path traversal protection via validate_path_within_repo() for
git_rm_force and git_checkout_theirs
- git_branch_delete defaults to safe delete (force=false)
HIGH:
- Replace silent .ok() with proper error propagation in git_commit,
git_merge_abort, git_rebase_abort, git_rm_force, git_checkout_theirs
- nativeDiffStat fallback parses numeric stats from git output
- nativeBatchInfo fallback counts staged/unstaged from porcelain status
MEDIUM:
- Wire up dead force param in removeWorktree()
- Read MERGE_MSG/SQUASH_MSG when commit message empty
- nativeLsFiles uses gitFileExec without fragile quote wrapping
- Fix operator precedence in git_ls_files
|
2026-03-15 20:02:10 -06:00 |
|