[Bug] git_add passes the files list to git without "--", so dash-leading names fail and options are accepted
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
- In a new git repo, add
.gitignorecontaining.env, then create.envand-weird.txt. - Call
git_addwithfiles: ["-weird.txt"]. - Call
git_addwithfiles: ["--force", ".env"].
Expected behaviour
-weird.txtis staged.- Nothing is staged.
--forceis treated as a path and rejected, and the ignored.envstays 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_diffandgit_logalready do this.- Add specs for a dash-leading filename and for
--force.
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.
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.