nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] git_add passes the files list to git without "--", so dash-leading names fail and options are accepted

Open addyCooks opened this issue 1 month ago • 2 comments

Summary

git_add appends each entry of files straight to git add. A real file named -weird.txt cannot be staged, and an entry such as --force is read by git as an option.

Steps to reproduce

  1. In a new git repo, add .gitignore containing .env, then create .env and -weird.txt.
  2. Call git_add with files: ["-weird.txt"].
  3. Call git_add with files: ["--force", ".env"].

Expected behaviour

  1. -weird.txt is staged.
  2. Nothing is staged. --force is treated as a path and rejected, and the ignored .env stays ignored.

Actual behaviour

1) Error: error: unknown switch `w'      staged: ""
2) Staged 1 file(s): A .env (+1, -0)      staged: ".env"

A spec for each case fails (- '' + '-weird.txt' and - '.env' + ''). git_add only asks for approval in normal mode (approval: (_args, mode) => mode === 'normal'), so in auto-accept the ignored file is staged without a prompt. git_commit still needs approval.

Environment

Windows 11, Node v22.22.3, Nanocoder 1.31.0 (main at 948a4e74)

Suggested fix

  • source/tools/git/git-add.tsx:39: build the call as ['add', '--', ...args.files]. git_diff and git_log already do this.
  • Add specs for a dash-leading filename and for --force.

addyCooks avatar Nov 02 '26 16:11 addyCooks

Picking this up.

Reproduced both cases on 948a4e7: -weird.txt fails with unknown switch \w', and files: ["--force", ".env"]stages the ignored.env` in auto-accept mode.

I have a fix ready that takes your suggested approach - ['add', '--', ...files], matching git_diff and git_log - with two specs against a real repository: one stages -weird.txt, the other asserts an option-shaped entry is rejected and nothing from the ignored set is staged. Opening the PR shortly.

Akaliup avatar Nov 02 '26 16:11 Akaliup

Hi @Akaliup, thanks for the PR! I've assigned this issue to you, so you're good to go this time. From next time, please ask to be assigned on the issue first and wait for a maintainer to assign it before opening a PR.

addyCooks avatar Nov 03 '26 06:11 addyCooks