Configure Git Bash shell profiles during Windows install#522
Configure Git Bash shell profiles during Windows install#522
Conversation
Git Bash (MSYS2/MinGW) prepends /mingw64/bin to PATH during shell initialization, which shadows the git-ai shim even when the Windows PATH has been correctly configured. Fix this by detecting Git for Windows installations and writing an export PATH line to ~/.bashrc or ~/.bash_profile, mirroring what install.sh already does for Unix shells. Closes #517 Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
|
|
|
review devin feedback |
PowerShell 5.1's Add-Content -Encoding UTF8 writes a UTF-8 BOM that causes 'command not found' errors in bash. Use .NET's UTF8Encoding(false) + AppendAllText instead to avoid the BOM. Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
| $gitForWindowsPaths = @( | ||
| (Join-Path $env:ProgramFiles 'Git\bin\bash.exe'), | ||
| (Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe'), | ||
| (Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe') | ||
| ) |
There was a problem hiding this comment.
🟡 Eager Join-Path evaluation with null env var aborts entire Git Bash config block
If ${env:ProgramFiles(x86)} is $null (e.g., on 32-bit Windows), the Join-Path call on line 453 throws a ParameterBindingValidationException during array construction, before the loop on line 456 ever executes. This causes the entire try block to jump to catch, skipping Git Bash configuration entirely — even if Git Bash is installed at one of the other checked paths ($env:ProgramFiles\Git\bin\bash.exe or $env:LOCALAPPDATA\Programs\Git\bin\bash.exe).
Root Cause
All three Join-Path calls on lines 452-454 are evaluated eagerly when constructing the $gitForWindowsPaths array. The null-guard $p -and on line 457 was intended to handle null paths, but it never gets reached because the exception occurs during array initialization.
$gitForWindowsPaths = @(
(Join-Path $env:ProgramFiles 'Git\bin\bash.exe'),
(Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe'), # throws if null
(Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe')
)With Set-StrictMode -Version Latest (line 2), Join-Path with a $null -Path parameter throws a terminating error. The fix is to guard each path construction against null, e.g., by only adding non-null paths to the array, or by using if checks before Join-Path.
Impact: On 32-bit Windows (rare but possible), Git Bash shell profile configuration is silently skipped with only a warning message, even when Git Bash is installed.
| $gitForWindowsPaths = @( | |
| (Join-Path $env:ProgramFiles 'Git\bin\bash.exe'), | |
| (Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe'), | |
| (Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe') | |
| ) | |
| $gitForWindowsPaths = @() | |
| if ($env:ProgramFiles) { $gitForWindowsPaths += Join-Path $env:ProgramFiles 'Git\bin\bash.exe' } | |
| if (${env:ProgramFiles(x86)}) { $gitForWindowsPaths += Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe' } | |
| if ($env:LOCALAPPDATA) { $gitForWindowsPaths += Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe' } | |
Was this helpful? React with 👍 or 👎 to provide feedback.
Configure Git Bash shell profiles during Windows install
Summary
Fixes #517. Git Bash (MSYS2/MinGW) prepends
/mingw64/bintoPATHduring its own shell initialization, which shadows thegit-aishim even when the Windows PATH has been correctly set bySet-PathPrependBeforeGit. This adds a new section toinstall.ps1that writesexport PATH="$HOME/.git-ai/bin:$PATH"into the user's~/.bashrcor~/.bash_profile, mirroring whatinstall.shalready does for Unix shells.The new block:
Program Files,Program Files (x86),LocalAppData\Programs).bashrcor.bash_profile(or creates.bashrcif neither exists).git-ai/binmarker to avoid duplicate entriesUpdates since last revision
Add-Content -Encoding UTF8with[System.IO.File]::AppendAllText()usingUTF8Encoding($false)to avoid writing a BOM that would causecommand not founderrors in bash on PowerShell 5.1.Review & Testing Checklist for Human
which gitresolves to~/.git-ai/bin/git(not/mingw64/bin/git)UTF8Encoding($false)+AppendAllText, but confirm the written file has no BOM bytes (EF BB BF) at the start, especially when.bashrcis newly created (no pre-existing file).bashrc.bashrcand the export line is correct. Consider whether creating.bashrcwhen a user has never used Git Bash is desirable, or if this should only append to existing filesNotes