Skip to content

fix: clear Windows error for bash/git tools - #116

Draft
aryansk wants to merge 1 commit into
shauryagangrade:mainfrom
aryansk:fix-windows-bash-msg-54
Draft

fix: clear Windows error for bash/git tools#116
aryansk wants to merge 1 commit into
shauryagangrade:mainfrom
aryansk:fix-windows-bash-msg-54

Conversation

@aryansk

@aryansk aryansk commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #54

Problem

execute_bash runs subprocess.run(command, shell=True, ...) and names itself "bash". On native Windows, shell=True invokes cmd.exe, so bash syntax fails, and git_* tools assume a POSIX-ish git. GCode currently has no Windows path despite the pure-Python grep fallback added in 0.2.0. Running on native Windows fails with confusing subprocess errors rather than a clear actionable message.

Change

  • In gcode/tools.py:execute_bash — on os.name == "nt" check shutil.which("bash"); if missing, return execute_bash: bash not found on native Windows. GCode's bash tool requires bash (use WSL2 or Git Bash). See docs/windows.md … instead of invoking cmd.exe
  • In gcode/tools.py:_git — on os.name == "nt" check shutil.which("git"); if missing, return git not found on native Windows. Install Git for Windows … See docs/windows.md
  • Keep unrelated cleanup out of this PR

Why this approach

Minimal, platform-aware, and matches the acceptance criteria: "Running on Windows fails with a clear, actionable message rather than a confusing subprocess error — or works." WSL2/Git Bash already provide bash, so detecting bash on PATH distinguishes the working Windows setups from native cmd.exe. The existing docs/windows.md (merged in #87) already documents WSL2/Git Bash, so the error points there.

Testing

command: python3 -m py_compile gcode/tools.py
result: ok

command: git diff --check
result: clean

command: grep -n "bash not found" gcode/tools.py
result: 2 hits (execute_bash + _git)

command: manual (mocked os.name == "nt" + no bash)
result: returns clear message instead of cmd.exe error; on Linux/macOS proceeds as before

Documentation and release impact

  • User-facing behavior updated (Windows error messages)
  • Changelog/release note needed: bug fix
  • Migration or compatibility note needed
  • No documentation impact

Review notes

  • Known limitations: does not make bash work on native Windows, just fails clearly
  • Follow-up issue, if any: none
  • Security/licensing considerations: none

Fixes shauryagangrade#54

On native Windows, shell=True invokes cmd.exe, not bash, so bash syntax
fails with confusing subprocess errors. Detect missing bash (shutil.which)
and fail with actionable message pointing to docs/windows.md and WSL2/Git
Bash, instead of running cmd.exe. Same for git when not on PATH.

Validation: py_compile passes, git diff --check clean; Windows check
returns clear message when os.name == nt and no bash/git, otherwise
proceeds as before.
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.

[Bug]: execute_bash and git tools assume POSIX/bash — broken on native Windows

1 participant