Skip to content

overhaul the source control panel and add hunk staging - #146

Open
ThinhNguyen2005 wants to merge 8 commits into
MuaraAI:mainfrom
ThinhNguyen2005:feat/scm-panel-overhaul
Open

ThinhNguyen2005 wants to merge 8 commits into
MuaraAI:mainfrom
ThinhNguyen2005:feat/scm-panel-overhaul

Conversation

@ThinhNguyen2005

@ThinhNguyen2005 ThinhNguyen2005 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Reworks the Source Control panel around a dedicated Git step runner (src/scm_git.rs) and adds hunk staging and conflict resolution while keeping the diff viewer updates from #138 and #144.

Conflict previews over 2 MiB stop before opening the resolver, Step::Resolve allows retrying git add if staging fails after writing, and WSL helper transport failures only fall back to wsl.exe for allowlisted read-only Git commands.

On Windows, focused scm_git::tests:: passed 12/12 and diff_view::tests:: passed 6/6. The full cargo test --bin fluxcode run reported 398 passed, 2 failed, and 7 ignored. Both failures (ext::host::tests::ext_host_smoke_test_with_node in unchanged src/ext/host.rs and proc::tests::isolated_job_terminates_spawned_process_and_children in unchanged src/proc.rs) reproduce with the same errors on main (3e17ecd) in this environment. cargo clippy --bin fluxcode -- -W clippy::all exited 0 with no new warnings in touched files.

@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@ThinhNguyen2005 is attempting to deploy a commit to the curzyori's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @ThinhNguyen2005!

Every pull request goes through the checks in CONTRIBUTING.md: this safety scan first, then the build, tests, code quality and a performance comparison against main (those start once a maintainer approves the run, because they execute your code). A maintainer reviews every pull request before it is merged.

Safety scan

Passed, with things a maintainer has to read before merging.

11 file(s) scanned · 🛑 critical: 0 · ⛔ high: 0 · 👀 review: 1 · ℹ️ info: 0

Finding Where Detail
👀 deletes files recursively src/scm_git.rs:1146 let _ = std::fs::remove_dir_all(&self.0);

Copy link
Copy Markdown
Collaborator

I reviewed the diff against main (3e17ecd): 11 files, +4541/-1311. I read src/scm_git.rs end to end, plus the diff viewer, incoming commits, and panel changes, and I checked CI and the translation table for this head (5583312).

What is wrong

  1. CI never built or tested this head. The Build and Pull request check runs finished as action_required, so the Windows, Linux, and macOS jobs did not run at all. The safety scan passed, but Vercel failed on this head while it passed on main (3e17ecd). The test numbers in the PR description come from a local Windows run, so they are the only test evidence so far. Please get a maintainer to approve the workflow run and confirm the Vercel failure is unrelated before merging.

  2. The two failing tests need one more fact. The description says ext::host::tests::ext_host_smoke_test_with_node and proc::tests::isolated_job_terminates_spawned_process_and_children fail in unchanged files. I confirmed neither src/ext/host.rs nor src/proc.rs is in this diff, so these changes did not cause the failures. Do they also fail on main? If they do, please say so in the PR. If they only fail on this branch, the branch needs a look before merge.

  3. Fifteen new strings have no Indonesian entry in src/i18n_id.rs, so tr() falls back to English for them in the Indonesian UI: "Checking for a Git repository…", "Commit the staged changes (Enter)", "Discard All", "Discard {n} files in {group}?", "Merge Conflicts", "Remove these files from the index and working tree.", "Restore the index and working tree to the last commit.", "Restore the original merge conflict in the working tree.", "Restore the working tree from the index.", "Running Git…", "Save or close the modified editor before discarding.", "Show {n} more files", "Switch to a branch before pushing or syncing.", "Untracked Files", "Untracked files will be deleted." The PR already adds translations for most new strings, so these fifteen look missed rather than deliberate.

  4. The diff viewer toolbar labels two toggles by opposite rules. In src/diff_view.rs, the mode button shows the mode it switches to ("Inline" while the view is split), but the context button shows the mode it is already in ("Full file" while the full file is shown). A reader takes one of them the wrong way. Please use one convention for both buttons.

  5. parse() in src/diff_view.rs still loses line numbers on a bare empty line inside a hunk. Any line that is not '+', '-', ' ', or '@@' falls into the else branch with no line numbers and without advancing the old/new counters, so every line after it gets the wrong number. Git always prefixes empty context lines with a space, so git-produced patches are fine. Does a patch from another tool with a truly empty context line reach this path, or is parse_diff_files the only path that matters for SCM diffs?

What is missing or unclear

  • scm_ignore in src/scm.rs reads and writes .gitignore with std::fs directly on the UI thread instead of going through write_doc_to_disk like the other file writes. Is that deliberate? For a WSL repo this writes through the UNC path rather than the helper.
  • Step::Preview and network steps in run_step skip the RPC helper entirely and always run through wsl.exe, while other steps prefer the helper and fall back only for allowlisted read-only commands. Is that intended, or should previews also prefer the helper when it is available?

What is good

  • src/scm_git.rs separates the Git layer from the panel: status parsing, the step runner, remote handling, and hunk staging live in one place, and src/scm.rs keeps the UI and workflow code.
  • The WSL fallback allowlist in read_only_git_args is careful, and the tests pin the dangerous cases: reset --hard, remote set-url, and -c alias.status=!git reset.
  • Hunk staging is guarded end to end. apply_hunk re-reads the status, compares the full current patch with the expected text, and refuses on any change. The test stages one hunk, checks the other edit stays unstaged, then unstages it again.
  • Conflict resolution has the same guard. Step::Resolve re-reads the file and refuses when the content no longer matches, and the 2 MiB cap applies even when the diff itself is small.
  • The tests are real integration tests against a temporary repo: 12 tests in scm_git.rs, including renames with spaces in the name, amend with a message only, and discard keeping index and worktree separate.
  • The incoming commits and fetch paths gained workspace generation guards, so a late background result no longer writes into a different workspace.
  • The hunk navigation in the diff viewer is wired up: the previous and next buttons call move_hunk and the Hunk n/total indicator shows the position.
  • preview_output enforces the 2 MiB cap by killing the child process when output grows past it, instead of trusting git to stop.

@ThinhNguyen2005

Copy link
Copy Markdown
Contributor Author

@MyKineID Pushed 527c24a to cover the review feedback and updated the PR description:

  • Indonesian translations: Added the 15 missing entries in src/i18n_id.rs, plus "No changes." and the conflict staging retry error string.
  • Diff toolbar toggles: Aligned both buttons in src/diff_view.rs to show the mode clicking switches to (Inline / Side by side and Changes only / Full file).
  • Conflict save/stage retry: Updated Step::Resolve in src/scm_git.rs so if git add fails after writing (for example on .git/index.lock), the error states the file was saved and retrying from the same tab stages without overwriting, while external edits are still rejected (added an .git/index.lock regression test).

Answers to the open questions:

  • Two Windows test failures: Both ext_host_smoke_test_with_node and isolated_job_terminates_spawned_process_and_children fail with the exact same errors on main (3e17ecd) in the same local environment; noted that in the PR description.
  • parse() bare empty lines: SCM virtual diffs always go through parse_diff_files(). parse() is the existing fallback from main for plain .diff/.patch files when parse_diff_files() returns no files, so it was left untouched to keep scope tight.
  • scm_ignore (std::fs): Left as-is from main to avoid growing this PR; moving .gitignore writes off the UI thread and through write_doc_to_disk for WSL makes sense as a separate follow-up.
  • WSL helper bypass for Step::Preview and network steps: Intentional. Network commands (fetch/pull/push) need non-interactive remote env vars and must not retry after a helper timeout, and Step::Preview caps stdout at 2 MiB while streaming in preview_output (the RPC helper buffers full output before returning).

Ready for a maintainer to approve the Build and Pull request check workflow runs on 527c24a. The Vercel failure is the fork preview authorization gate (curzyoris-projects), unrelated to the Rust build.

Copy link
Copy Markdown
Collaborator

Follow-up review, only for the new commit 527c24a ("fix conflict staging retries and source control labels") since my review of 5583312.

What is wrong

  • 16 strings this PR introduces in src/scm.rs still have no Indonesian entry in src/i18n_id.rs, so the Indonesian UI falls back to English for them. The new commit added 17 translations, but these are still missing:
    • "Staged Changes", src/scm.rs:379
    • "Committing…", src/scm.rs:758, and "Committed", src/scm.rs:762
    • "Pushing…", src/scm.rs:771, and "Committed and pushed", src/scm.rs:775
    • "Syncing…", src/scm.rs:793
    • "Discarding…", src/scm.rs:961, "Unstaging…", src/scm.rs:963, "Staging…", src/scm.rs:965 and :2851
    • "Initializing…", src/scm.rs:1289
    • "Fetching…", src/scm.rs:1302, :1443, :2649
    • "Graph", src/scm.rs:1939
    • "Pulling…", src/scm.rs:2626, "Pushing…", src/scm.rs:2636
    • "Discard", src/scm.rs:1529 and :1694
    • "Stage" and "Unstage", src/scm.rs:1711
      I checked every tr() call in the changed files against the table, and these are the full remainder. On main these were plain literals ("Stage"/"Unstage" tooltips, "Staged Changes", "Graph"), and this PR converted them to tr() calls, so the gap is new to this PR. Did you check the full list of tr() strings in the changed files against the table, or only the ones from my last review?
  • No CI build or test ran on this head. The only check runs on 527c24a are the two safety scans, both passing, and Vercel failed with "Authorization required to deploy". The Build and Pull request check runs never started, they need a maintainer to approve the run on a fork PR. The PR body still reports the old test run (398 passed, 2 failed), which ran before this commit, so the new tests in src/scm_git.rs have no CI evidence yet.

What is missing or unclear

  • Did you run the new tests in src/scm_git.rs locally (the index.lock staging failure, the stale file case, the retry after the lock is removed)? The PR body numbers predate this commit, so I cannot tell from the PR whether they pass.
  • The test asserts the staging error contains "index.lock". Does git print that exact text on Windows too, where you run the tests? If git ever words that error differently, this assertion breaks even though the behaviour is right.

What is good

  • The label fix in src/diff_view.rs:620 is right. The button now shows the view it switches to ("Changes only" while the full file is shown), which matches the sibling diff-mode button next to it, and it fixes the swapped labels from my last review.
  • The 17 new Indonesian entries in src/i18n_id.rs cover the strings from my last review, including the new "Conflict resolution was saved, but staging failed: {error}" message. I checked each one is used in the code.
  • The retry design in src/scm_git.rs is sound. Accepting a file that already holds the resolved content makes a retry after a failed staging safe, skipping the write when nothing changed is the right guard, and the wrapped error tells the user the resolution is already on disk when git add fails. The test covers the lock, the stale file, and the retry after the lock is removed, which is the exact sequence a user hits.
  • The stale check reads expected.len().max(resolved.len()) plus one byte, so a file longer than both still fails the check instead of passing on a prefix match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants