Skip to content

fix(core): find Git Bash when git is under mingw64 - #57327

Open
SKaranjaN wants to merge 2 commits into
anomalyco:devfrom
SKaranjaN:fix/gitbash-mingw64-path
Open

SKaranjaN wants to merge 2 commits into
anomalyco:devfrom
SKaranjaN:fix/gitbash-mingw64-path

Conversation

@SKaranjaN

@SKaranjaN SKaranjaN commented Oct 20, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #57310

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

gitbash() assumed git.exe lived in Git\cmd and looked two directories up for bin\bash.exe. Inside Git Bash, git is Git\mingw64\bin\git.exe, so that path misses and the shell tool falls back to PowerShell.

It now walks up from the git that is actually on PATH and checks bin\bash.exe and usr\bin\bash.exe. That covers Git\cmd, Git\mingw64\bin, and MSYS2's ucrt64\bin. If bash is not next to that git, it asks git --exec-path once and walks from there. An explicit gitbash config path is unchanged.

How did you verify your code works?

From packages/core:

  • bun test test/shell-select.test.ts — 4 passed, including a fake Git\cmd, Git\mingw64\bin, and MSYS2 ucrt64 layout, plus this machine's real install with Git\mingw64\bin first on PATH (gitbash() returned C:\Program Files\Git\bin\bash.exe)
  • bun test test/shell.test.ts — 10 passed

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #54104

Inside Git Bash, git.exe is mingw64\bin\git.exe, so looking two levels up for bin\bash.exe misses and the shell tool falls back to PowerShell.
@SKaranjaN

Copy link
Copy Markdown
Author

GitHub won't let me request reviewers from a fork. @thdxr could you take a look when you have a minute? This is the Git Bash path bug in #57310.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right. In a simulated Git for Windows layout on Linux (the #57310 script, with process.platform forced to win32), gitbash() returns undefined on the base when git comes from Git/mingw64/bin or MSYS2 ucrt64/bin. With this PR it returns Git/bin/bash.exe and msys64/usr/bin/bash.exe. Git/cmd still works. Core shell tests and typecheck pass. The new tests only run on Windows, so on Linux they check nothing.

Public API unchanged.

One behaviour concern: when no bash.exe is found, the failure isn't cached, so git --exec-path runs again on every lookup (see inline). Small test cleanup too, also inline.

Related: #54104

Comment thread packages/core/src/shell/select.ts Outdated
const exec = gitExecPath(git)
if (exec) file = bashNear(exec)
}
if (!file) return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a successful lookup goes into bashForGit. When git is a real .exe but no bash.exe is found near it, every gitbash() call runs Bun.spawnSync([git, "--exec-path"]) again. That call blocks. gitbash() runs from both win() and full(), so one resolve() or list() can start git several times, and it happens again on every later call. Could you also remember the "not found" result per git path, or cache the --exec-path output?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cached. A miss is stored on that git path, so later lookups return without spawning git --exec-path.

Comment thread packages/core/test/shell-select.test.ts Outdated
expect(path.normalize(ShellSelect.gitbash() ?? "")).toBe(path.normalize(path.join(msys, "usr/bin/bash.exe")))
})

test("finds the installed Git Bash when mingw64/bin is first on PATH", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test depends on whether C:\Program Files\Git exists on the machine running it, and it passes silently when it doesn't. The fake-layout test above already covers the fix. Please drop this one, and the explicit gitbash path test (behaviour this PR doesn't change), so the test file stays small.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed both. The fake Git for Windows and MSYS2 layouts are the ones that stay.

A missed lookup was spawning git --exec-path on every call. Cache that miss, and drop the tests that depend on a local Git install or on unchanged behavior.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: gitbash() fails when git resolves to mingw64/bin (e.g. inside Git Bash), shell falls back to pwsh

1 participant