fix: scope gitm commit to the files the user selected#40
Merged
Conversation
git.Commit ran a bare `git commit -m`, which commits the entire index. Any file that was already staged (porcelain status A/M) but NOT chosen in the file picker therefore leaked into the commit under the same message. Scope the commit with `git commit -- <files>` (git's default --only mode), so only the user's selection is committed and other staged files are left untouched and uncommitted. Extract the shared porcelain-prefix stripping into cleanPorcelainPaths and reuse it across StageFiles, UntrackFiles, and Commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
✅ All checks passed (Go 1.26) Coverage: 69.9% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running
gitm commit -r <repo>and selecting only one file in the picker, the resulting commit also swept in files the user did not select — specifically files that were already staged (porcelain statusA/M) before the selection. They were committed under the same message, and disappeared from the next run's picker, confirming the leak.Root cause
git.Commitran a baregit commit -m <msg>, which commits the entire index.StageFilescorrectly staged only the selected files, but any pre-staged file was already in the index and got committed too.Fix
Scope the commit to an explicit pathspec:
git commit -m <msg> -- <files>. This is git's default--onlymode — it commits only the named paths and disregards changes staged for other paths, leaving those other files staged and uncommitted so they can be committed separately later.git.Commitnow takes the selected files and scopes the commit.cleanPorcelainPaths, reused byStageFiles,UntrackFiles, andCommit.Tests
TestCommitOnlySelectedFiles(real temp repo, no mocks per AGENTS.md): pre-stages an unselected new file, selects a different modified file, commits, and asserts the commit contains only the selected file while the unselected one stays staged. Fails against the old bare-commit behaviour.-race;make lintclean.🤖 Generated with Claude Code