Repository navigation
feat: add commit_files for multi-path commits and fix repo-relative path resolution for nested config dirs - #679
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
commit_files for multi-path commits and fix repo-relative path resolution for nested config dirs
🎨 Storybook previewUpdated for 0e785af
|
darkmatteragent
left a comment
There was a problem hiding this comment.
Review — APPROVE
69e2e8d2c82f · 0 findings
Approve: solid hardening — every producer/consumer boundary checks out. - All app callers pass the git toplevel plus repo-relative filenames, which repo_relative_path reproduces unchanged; the nested-config-dir case is fixed as intended. - Per-hunk commit/discard keeps hunk granularity through find_hunk_by_hash; no sibling-row mutation exists. - Escape/symlink paths fail closed before mutation, and the index.write() reorder preserves intent-to-add entries, with new tests locking both in.
No findings.
|
No findings. reviewed: 69e2e8d — 2026-09-04T07:53Z verdict: approve findings: 0
Run details
|
📋 PR Overview
🔬 Coverage
|
| @@ -425,8 +482,7 @@ pub fn restore_hunk(dir: &str, path: &str, hunk: &str) -> Result<()> { | |||
| /// as an empty blob instead. | |||
| pub fn commit_hunk(dir: &str, path: &str, hunk: &str, message: &str) -> Result<CommitInfo> { | |||
There was a problem hiding this comment.
Severity 2 — not blocking
commit_hunk still has the write-before-bail shape this PR fixes in commit_files: further down (line 550) the index is written before the nothing to commit check. It's practically unreachable today (find_hunk_by_hash just found the hunk in the live diff), but the lookup→commit window is a check-then-act race, and when the bail does fire it clobbers intent-to-add entries the same way. Same two-line move as in commit_files?
| @@ -318,8 +376,7 @@ fn index_entry_differs_from_head( | |||
| /// drift row alive. Purely unstaged drift leaves the index untouched. | |||
| pub fn restore_hunk(dir: &str, path: &str, hunk: &str) -> Result<()> { | |||
There was a problem hiding this comment.
Severity 2 — not blocking
Now that paths here are dir-relative, restore_hunk/commit_hunk are only correct with dir = repo root: find_hunk_by_hash and file_diff_contents still match workdir-relative names, so a future caller passing a nested config dir would look a hunk up under one convention and resolve the file under the other. Worth a one-line comment on these two functions ("callers must pass the repo root until the query side is dir-relative too") so the first nested-dir caller finds out at review time instead of at runtime?
Juanpe Bolívar (arximboldi)
left a comment
There was a problem hiding this comment.
Oh damn! I guess I missed #655 (comment) before writing my review comment in #655 ... I think this probably solves my issues! Looking forward to re-try once this is in :)
|
|
|
||
| /// Commit only the requested files, interpreting each path relative to `dir` | ||
| /// and leaving unrelated worktree changes out of the commit. | ||
| pub fn commit_files(dir: &str, paths: &[&str], message: &str) -> Result<CommitInfo> { |
There was a problem hiding this comment.
Empty selection creates a commit
The new commit_files API accepts an empty paths slice. In a repository without a first commit, this skips staging, writes an empty index, and creates an empty commit. The “nothing to commit” check only runs when parent exists.
Current callers always select one file, so this is non-blocking. Reject an empty selection before touching the index, and add a test that checks that staged files survive.
commit_files with an empty path list on an unborn HEAD cleared the index, wrote it to disk and recorded an empty root commit. It now rejects an empty path list up front and, on an unborn HEAD, bails when nothing ended up staged, mirroring commit_all. commit_hunk wrote the reset index to disk before checking whether the hunk changed anything, so a no-op hunk unstaged the user's other changes and then failed. The index is now written only once a commit will be created. Adds regression tests for all three cases.
|
Pushed 0e785af with two small fixes so this can land ahead of the secrets stack:
Three regression tests cover these; they fail without the fix and all 42 |
|
There was a problem hiding this comment.
No issues found across 2 files
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Turn on auto-fix | Re-trigger cubic









Summary
This is to improve/harden the git layer to make it easier and less bug-prone supporting nested config dirs, based on this comment from Alex Shabalin (@alex-sparus) here: #655 (comment)
It also proactively adds the
commit_filesfunction which was in the PR that inspired said comment.The main thing to look at is the
repo_relative_pathmethod -- the correctness of its logic as well as its call sites.Test Plan
New unit tests.
Docs