Skip to content

在Windows下安装了git.exe,仍然提示deepcode: Deep Code on Windows requires Git Bash. Install Git for Windows and ensure git.exe is available in PATH. #38

@facat

Description

@facat

PS C:\Users\abc> deepcode
deepcode: Deep Code on Windows requires Git Bash. Install Git for Windows and ensure git.exe is available in PATH.
PS C:\Users\abc> git.exe
usage: git [-v | --version] [-h | --help] [-C ] [-c =]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--no-lazy-fetch]
[--no-optional-locks] [--no-advice] [--bare] [--git-dir=]
[--work-tree=] [--namespace=] [--config-env==]
[]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history
backfill Download missing objects in a partial clone
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify tags

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help ' or 'git help '
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

使用的是windows 11系统,deepcode -v 是0.1.18。git-bash也是有的。

以下是deepseek,供参考。
● 已经完成了完整的代码分析。以下是结论:

────────────────────────────────────────────────────────────

findGitBashPath() 完整调用路径

cli.tsx L102 configureWindowsShell()
→ setShellIfWindows() [shell-utils.ts L17]
→ findGitBashPath() [shell-utils.ts L23]
→ findAllWindowsExecutableCandidates("git") [L158]
→ execFileSync("where.exe", ["git"]) [L160] ← 查找 PATH
+ WINDOWS_GIT_LOCATIONS (2个硬编码路径) [L6-9]
→ filterWindowsExecutableCandidates() [L170] ← 检查文件存在性
→ 对每个候选git路径,拼合 ../../bin/bash.exe 并检查是否存在
→ 全部不存在则抛出错误

你的系统上发生了什么

从我刚才执行的诊断命令可以看到,你的环境中 where.exe 不可用。这意味着 findAllWindowsExecutableCandidates 的第一步就抛异常了,代码捕获后只回退到
2 个硬编码路径:

C:\Program Files\Git\cmd\git.exe
C:\Program Files (x86)\Git\cmd\git.exe

如果你的 Git 安装在这两个路径之外(例如装了新版 Git 但选了自定义目录、或者通过 Scoop/Chocolatey/Portable
安装),那么这两个路径都不存在,filterWindowsExecutableCandidates 返回空数组,for 循环零次执行,直接命中 throw new Error(...)

根本原因总结

│ 环节 │ 具体问题 │
│ 查找手段单一 │ 只用 where.exe 查 PATH,没有用 reg query 查注册表,也没有检查 Gi… │ │ 硬编码路径有限 │ 只写了两个标准安装路径,无法覆盖自定义安装、Scoop、Chocolatey、Portab… │ │ 路径推算脆弱 │ git.exe → ../../bin/bash.exe硬编码了 Git for Windows 的标准目录布… │ │ 错误信息不准确 │ 说"确保 git.exe 在 PATH 中",但实际上即使 git.exe 在 PATH 里,只要.… │

修复方向(如果你要改源码)

有几种改法:

  1. 增加更多 Fallback 路径 — 在 WINDOWSGITLOCATIONS 之外,扫描 %USERPROFILE%\scoop\apps\git\current、注册表中的 Git 安装路径
  2. 直接从 reg query 读取 Git 安装位置 — HKLM\SOFTWARE\GitForWindowsHKCU\Software\GitForWindows
  3. 不推算路径,直接找 bash.exe 本身 — 用 where.exe bash 或扫描常见位置(Program Files\Git\bin\bash.exeProgram Files\Git\usr\bin\bash.exe
  4. 改进错误信息 — 区分"没找到 git.exe"和"找到了 git.exe 但没找到配套的 bash.exe"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions