I'm trying to perform git add --patch -- <file>
and the command never completes. The MINGW64 shell just displays "The system cannot find the path specified."
When narrowing down the cause by setting GIT_TRACE=1 and trying to run some of the component commands, I found that the error is caused by the --interactive option and the same effect is seen no matter what git command is being run.
Setting GIT_TRACE=1 on the following interactive command gives the output shown:
$ GIT_TRACE=1 git add --interactive -- .gitignore
19:16:47.185964 git.c:350 trace: built-in: git 'add' '--interactive' '--' '.gitignore'
19:16:47.185964 run-command.c:336 trace: run_command: 'add--interactive' '--' '.gitignore'
19:16:47.215964 git.c:564 trace: exec: 'git-add--interactive' '--' '.gitignore'
19:16:47.215964 run-command.c:336 trace: run_command: 'git-add--interactive' '--' '.gitignore'
19:16:47.345964 git.c:350 trace: built-in: git 'rev-parse' '--git-dir'
19:16:47.375964 git.c:350 trace: built-in: git 'rev-parse' '--show-prefix'
19:16:47.405964 git.c:350 trace: built-in: git 'config' '--get-colorbool' 'color.interactive' 'false'
19:16:47.436965 git.c:350 trace: built-in: git 'config' '--get-colorbool' 'color.diff' 'false'
19:16:47.466965 git.c:350 trace: built-in: git 'config' '--get-color' 'reset'
19:16:47.496965 git.c:350 trace: built-in: git 'config' '--get' 'diff.algorithm'
19:16:47.546965 git.c:350 trace: built-in: git 'config' '--bool' '--get' 'diff.compactionheuristic'
19:16:47.576965 git.c:350 trace: built-in: git 'config' '--get' 'interactive.difffilter'
19:16:47.606965 git.c:350 trace: built-in: git 'config' '--bool' '--get' 'interactive.singlekey'
19:16:47.636965 git.c:350 trace: built-in: git 'rev-parse' '--git-dir'
19:16:47.666965 git.c:350 trace: built-in: git 'update-index' '--refresh'
19:16:47.793965 git.c:350 trace: built-in: git 'ls-files' '--' '.gitignore'
The system cannot find the path specified.
19:16:47.843965 git.c:350 trace: built-in: git 'diff-index' '--cached' '--numstat' '--summary' '4b825dc642cb6eb9a060e54bf8d69288fbee4904' '--' '.gitignore'
19:16:47.873966 git.c:350 trace: built-in: git 'diff-files' '--numstat' '--summary' '--raw' '--' '.gitignore'
Trying to add the file without the interactive option works as expected. The operation only fails when there is an interactive (or patch) option added.
Note that I initially had the following issue when trying to run the command:
Can't locate Git.pm in @INC (you may need to install the Git module) (@INC contains: /mingw64/share/perl5/site_perl D:/Apps/StrawberryPerl/perl/site/lib D:/Apps/StrawberryPerl/perl/vendor/lib D:/Apps/StrawberryPerl/perl/lib) at C:\Program Files\Git\mingw64/libexec/git-core\git-add--interactive line 7.
BEGIN failed--compilation aborted at C:\Program Files\Git\mingw64/libexec/git-core\git-add--interactive line 7.
However after copying the Git.pm and Error.pm modules to the perl include folder, the problem changed to the one described at the top of this question.
Finally, as a further attempt at figuring this out I ran the command in a Windows command prompt (cmd.exe) and had a totally different error:
c:\code\proj>git add --patch .gitignore
error: wrong number of arguments
usage: git config [<options>]
Config file location
--global use global config file
--system use system config file
--local use repository config file
-f, --file <file> use given config file
--blob <blob-id> read config from given blob object
Action
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value
[value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-e, --edit open an editor
--get-color find the color configured: slot [default]
--get-colorbool find the color setting: slot [stdout-is-tty]
Type
--bool value is "true" or "false"
--int value is decimal number
--bool-or-int value is --bool or --int
--path value is a path (file or directory name)
Other
-z, --null terminate values with NUL byte
--name-only show variable names only
--includes respect include directives on lookup
--show-origin show origin of config (file, standard input, blob, command line)
config --get-color color.interactive.prompt bold blue: command returned error: 129
I checked my git config files and I don't set this option so I'm guessing it's a default that's set somewhere.
Apart from the obvious aspect of the question (i.e. getting the --interactive
or --patch
options to work as expected), I'd also appreciate any advice or tips on debugging this further. The various TRACE options I used didn't really highlight where the problem was, apart from showing me that it was the --interactive
option that was the issue.
In short - the answer here was to upgrade the version of Git for Windows used. My version was 2.10.1.windows.1 which is a couple of years old. I upgraded to 2.19.0.windows.1 and all is now working as it should.
So the issue might be because there was an error in that version of git, in which case hopefully this will give anyone else using that version a heads-up. Alternatively, there could have been an issue with my installation somewhere along the line, which was automatically corrected by the new git installation. In that case, consider this an idea of things to try if you are having similar problems.
Not a particularly fulfilling answer - but an answer nonetheless.