nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] autoCommit treats the edited file name as a git glob and commits other files too

Open addyCooks opened this issue 1 month ago • 2 comments

Description

commitFile in source/services/auto-commit.ts passes the file path to git as a pathspec in git add -- (line 133), git diff --cached -- (lines 134-141) and git commit -m ... -- (line 146). The -- only stops option parsing. Git still treats [ab].txt as a glob, so it also matches a.txt and b.txt. Those files, including the user's uncommitted edits, end up in the agent's commit.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 5c2e693)
  • Git: 2.55.0.windows.3
  • Provider / Model: not relevant (reproduced by calling maybeAutoCommit directly)

Steps to Reproduce

  1. Create a repo with committed a.txt and b.txt. Turn on nanocoder.autoCommit.
  2. Edit both files without committing.
  3. Let the agent create a new file named [ab].txt.
  4. Run git show HEAD --name-only --format=.

Expected Behavior

Only [ab].txt is committed.

Actual Behavior

The commit chore: update [ab].txt contains all three files:

[ab].txt
a.txt
b.txt

Suggested Fix

Make git treat the path literally in all three calls: set GIT_LITERAL_PATHSPECS=1 for these git commands, or use git --literal-pathspecs, or prefix the path with :(literal). Add a test with a glob-named file next to the other cases in source/services/auto-commit.spec.ts.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

addyCooks avatar Oct 08 '26 16:10 addyCooks

hey @addyCooks, @akramcodez, i would like to work on this issue could please assign this to me.

plan - i'd like to take this. I'll make commitFile's git calls use --literal-pathspecs so file names aren't read as patterns.

karthikponna avatar Oct 09 '26 05:10 karthikponna

Good approach @karthikponna, go for it !

addyCooks avatar Oct 09 '26 06:10 addyCooks