Skip to content

fix: scope gitm commit to the files the user selected#40

Merged
alexandreafj merged 1 commit into
masterfrom
fix/commit-leaks-unselected-staged-files
Jun 2, 2026
Merged

fix: scope gitm commit to the files the user selected#40
alexandreafj merged 1 commit into
masterfrom
fix/commit-leaks-unselected-staged-files

Conversation

@alexandreafj
Copy link
Copy Markdown
Owner

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 status A/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.Commit ran a bare git commit -m <msg>, which commits the entire index. StageFiles correctly 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 --only mode — 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.Commit now takes the selected files and scopes the commit.
  • Extracted the duplicated porcelain-prefix stripping into cleanPorcelainPaths, reused by StageFiles, UntrackFiles, and Commit.

Tests

  • Added 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.
  • Full suite passes with -race; make lint clean.

🤖 Generated with Claude Code

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>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

✅ All checks passed (Go 1.26)

Coverage: 69.9%

@alexandreafj alexandreafj merged commit 856a6c7 into master Jun 2, 2026
1 check passed
@alexandreafj alexandreafj deleted the fix/commit-leaks-unselected-staged-files branch June 2, 2026 06:56
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