Skip to content

fix: manual repo root discovery for staging; fix stale tabs.length - #11

Merged
kennethfan merged 10 commits into
masterfrom
dev
Jul 18, 2026
Merged

kennethfan merged 10 commits into
masterfrom
dev

Conversation

@kennethfan

Copy link
Copy Markdown
Owner

修复内容

Bug: 保存第二个冲突文件后 staging 失败

在 watcher 模式下,如果有 2+ 冲突文件,保存第二个文件时 staging 失败,文件仍然保持 UU (both modified) 状态。

Root Cause 1 — git2 自动发现 .git 失败

stage_in_git 调用 git2::Repository::open(parent) 从文件所在目录向上搜索 .git,但在深层 Java 包路径下搜索失败(如 com/infloww/creator/controller),返回 NotFound。

Root Cause 2 — CLI fallback CWD 错误

CLI 回退 git add <file> 依赖进程 CWD 来定位 .git 目录,而 Tauri 打包应用的 CWD 不可控,导致 CLI 也失败。

Root Cause 3 — 静默吞错误

原代码中 staging 失败仅 eprintln!,不返回前端,用户完全不知情。

Root Cause 4 — 闭包陈旧

handleOpenConflictedFile 中 await 后使用闭包捕获的旧 tabs.length 计算新 tab 索引,导致切换到错误的 tab。

改动

save.rs

  • 新增 find_repo_root() 辅助函数,手动向上遍历查找 .git 目录/文件
  • stage_in_git 改用两步法:先找 repo root,再从 root 打开仓库
  • stage_in_git_cli 添加 -C <parent> 参数,指定 git 从文件所在目录开始搜索
  • 双重失败时 return Err 到前端,不再静默

App.tsx

  • 三个 handler 中 tabs.length 改为 tabsRef.current.length,避免闭包捕获旧值

- Rust backend: blame_side() runs git blame <ref> -- <file> directly on
the tracked file path (no temp file), supporting both HEAD and MERGE_HEAD
- parser: add SideBlame type wrapping local + remote BlameMap
- frontend: load SideBlame on file open, render blame tooltips on both
side panes (Yours + Theirs) with dotted underline hover indicator
- CSS: conflict-side-line--blamed style for hover cue
- clippy clean, 117+20 Rust tests, 126 frontend tests all passing
- Cmd+Shift+O or welcome button opens a Git repo directory
- Auto-starts the conflict watcher and adds the repo
- WatchedRepoPanel auto-expands with the repo's conflicted files
- Single-conflict-file repos auto-open the file
- ShortcutsOverlay updated with new shortcut
- ADR 001 documents the design decision
The save command created .splice.bak backup files but never cleaned them up,
leaving clutter in the user's repo directory after resolving conflicts.
Now the backup is removed after the file is written successfully.

The session's undo/redo stack in memory still provides crash protection
during the editing session.
In directory (non-mergetool) mode, saving resolved content only updated
the file on disk but did not stage it in git's index. Git continued to
show the file as 'both modified' in On branch dev
Your branch is ahead of 'origin/dev' by 9 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   src-tauri/src/commands/save.rs.

Now after a successful save in non-mergetool mode, we run  to
stage the file, properly marking the conflict as resolved.
- stage_in_git now tries git2 first, falls back to git add via CLI
- Added test_stage_multiple_files_in_repo to verify multi-file staging
- Both stage files show as correctly resolved after sequential staging
… App.tsx

- Add find_repo_root() helper that walks up from file path to find .git
  directory, replacing reliance on git2::Repository::open auto-discovery
  which failed on deep package paths (e.g. Java/maven projects)
- Use git -C <parent> add <file> in CLI fallback to avoid CWD issues
  in bundled Tauri apps
- Fix three handlers in App.tsx (handleOpenFile, handleOpenConflictedFile,
  handleOpenDirectory) to use tabsRef.current.length instead of stale
  tabs.length from closure capture
@kennethfan
kennethfan merged commit 3490aee into master Jul 18, 2026
2 checks passed
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.

1 participant