Repository navigation
Fix two Windows-only bugs in Git Bash - #224
Open
anarchitect wants to merge 2 commits into
Open
anarchitect wants to merge 2 commits into
anarchitect wants to merge 2 commits into
Conversation
isCloud() only matched OSTYPE 'msys'. Some Git for Windows builds report 'cygwin' instead, including the ARM64 CLANG build. On those the leading slash in 'gh api /' is rewritten to a filesystem path, the call fails, and github.com is misidentified as GHES v2.20. That is not a cosmetic warning. It silently changes the output: the Is_Empty column is dropped from the header, leaving 35 columns instead of 36, and Protected_Branch_Count reads the GHES-only protectedBranches field, so it reports null on every row. Match msys, cygwin and win32 so the escaped endpoint is used on all Windows shells.
On Windows, jq emits CRLF line endings. Bash splits command substitution on IFS, which contains LF but not CR, so every base64 token produced by 'jq -r .[] | @base64' keeps a trailing carriage return. base64 --decode rejects that byte and prints 'base64: invalid input' to stderr, then decodes the valid prefix anyway. The output was therefore correct but accompanied by one error line per field read: 57 lines for a three repository organization, and proportionally more for a real one. Strip CR before decoding at all nine call sites.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes two Windows-only Git Bash issues that impact GitHub API endpoint detection and parsing behavior, preventing incorrect GHES/cloud detection and eliminating noisy base64: invalid input stderr output during repository inventory runs.
Changes:
- Broaden
isCloud()Windows detection by matchingOSTYPEviacasepatterns (e.g.,msys*,cygwin*,win32) and using the Windows-safegh api //path form. - Strip
\rbeforebase64 --decodeat the various_jqhelper call sites to avoid CRLF-related decode warnings on Windows.
Show a summary per file
| File | Description |
|---|---|
| gh-repo-stats | Improves Windows/Git Bash compatibility for cloud detection and base64-decoding of jq @base64 outputs. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Comment on lines
1007
to
1011
| REPO_DATA=$1 | ||
| # Convert the format to JSON | ||
| _jq() { | ||
| echo -n "${REPO_DATA}" | base64 --decode | jq -r "${1}" | ||
| echo -n "${REPO_DATA}" | tr -d '\r' | base64 --decode | jq -r "${1}" | ||
| } |
jackpotpot342-prog
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two independent Windows-only bugs in Git Bash. Both are reproducible on a stock Git for Windows install; neither affects Linux or macOS.
The two commits are independent and separately revertable. Happy to split this into two PRs if you would rather take them separately — say the word and I will.
1.
isCloud()misdetects Windows, silently corrupting the outputisCloud()matchesOSTYPEexactly againstmsys:Not every Git for Windows build reports that value. On the ARM64 CLANG build:
The check falls through to the Unix branch, MSYS rewrites the leading slash into a filesystem path, and the call fails:
This is not just a warning. With
isCloud()failing, github.com is treated as GHES v2.20, which changes what gets written to the CSV:Is_EmptycolumnProtected_Branch_Count0nullon every rowThe last one is the reason I would treat this as more than cosmetic:
isCompatibleGHESVersionroutes the parser to the GHES-onlyprotectedBranchesfield instead ofbranchProtectionRules, so branch protection silently reads as null for the whole inventory. A user has no indication the numbers are wrong.Fixed by matching all the values Windows shells actually report:
Globs rather than exact matches, since
msysandcygwinboth appear with version suffixes on some builds.2.
base64: invalid inputon every field readEvery run on Windows emits a large volume of:
Cause.
jqon Windows writes CRLF. Bash splits command substitution onIFS, which contains LF but not CR, so every token fromjq -r '.[] | @base64'retains a trailing carriage return:GNU coreutils
base64rejects the stray byte, writes to stderr, then decodes the valid prefix anyway — so output is currently correct.Why I would still fix it rather than leave it:
base64that exits non-zero on invalid input would make_jqreturn empty and blank every field — turning a loud non-issue into a silent data-loss bug.Fixed by stripping CR before decoding, at all nine
_jqcall sites:tr -d '\r'is a no-op on Linux and macOS, so this is inert on non-Windows platforms.Verification
Run against a live organization on Git Bash (Git for Windows, ARM64), before and after.
Before:
After:
No endpoint errors, no base64 output, correct column count and values.
bash -npasses.I have not been able to test on a GHES instance, so a second opinion on the
isCloud()change from anyone with GHES access would be welcome — though the change only affects which endpoint string is used on Windows, and leaves the Unix path untouched.