René's URL Explorer Experiment


Title: fix(git): tolerate noisy git rev-parse output in is_git_project by bearomorphism · Pull Request #1980 · commitizen-tools/commitizen · GitHub

Open Graph Title: fix(git): tolerate noisy git rev-parse output in is_git_project by bearomorphism · Pull Request #1980 · commitizen-tools/commitizen

X Title: fix(git): tolerate noisy git rev-parse output in is_git_project by bearomorphism · Pull Request #1980 · commitizen-tools/commitizen

Description: Description Closes #1497. Why Users running commitizen via uv tool install commitizen inside Git Bash on Windows 11 encounter NotAGitProjectError even though running git rev-parse --is-inside-work-tree manually in the same shell returns true. Commands that require a git context — cz commit, cz bump, cz changelog — all raise the error, while read-only commands such as cz info and cz ls succeed because they never call is_git_project(). The root cause is the single-line check at commitizen/git.py:316 (master): return c.out.strip() == "true" Some shell wrappers — including Git Bash's colour-prompt infrastructure and certain terminal emulators on Windows — inject ANSI CSI escape sequences (e.g., \x1b[0m) into subprocess standard output. When that happens, c.out.strip() yields "\x1b[0mtrue" rather than the bare string "true", the strict equality check fails silently, and is_git_project() returns False, triggering the error even inside a valid work tree. This was surfaced during the #1964 audit: "Depending on subprocess setup with uv tool install on git-bash for Windows, [the output] may not match exactly." Because the original reporter's exact environment couldn't be reproduced locally, the new --debug logging path provides the next-best diagnostic: any future reporter can run cz --debug commit and see the exact bytes returned by git rev-parse. What changed File Change commitizen/git.py Add _ANSI_ESCAPE compiled regex; rewrite is_git_project() to trust the exit code first, strip ANSI codes, then exact-match "true"; add logger.debug for both failure paths tests/test_git.py Add five targeted regression tests: inside-work-tree, outside-repo, ANSI-prefixed output (the #1497 case), bare-repo interior, and substring-true rejection (parametrised) How it works Exit-code-first gate: if git rev-parse returns non-zero, we are definitively outside any git context — is_git_project() returns False immediately, independent of output parsing. This handles the genuine "not a repo" case cleanly and makes the diagnostic log message (rc=128) unambiguous. ANSI stripping before comparison: the module-level constant _ANSI_ESCAPE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]") (compiled once at import time) covers all CSI sequences — SGR colour codes, cursor commands, and resets. It is applied via .sub("", c.out) before .strip().lower(). Exact match, not substring (the non-obvious choice): after stripping ANSI codes the cleaned output is compared with == "true". An earlier draft used .lower().endswith("true"), which also accepts "untrue" or "nottrue" — strings git rev-parse would never emit, but which a defensive matcher should still reject. The ANSI-strip step is the only looseness introduced; the final comparison remains a full-string equality check. logger.debug diagnostics: both failure paths (non-zero exit and unexpected textual output) emit a DEBUG-level message that includes rc, out, and err. Running cz --debug commit will now surface the exact bytes returned by git rev-parse, eliminating guesswork for future environment-specific reports. Backward compatibility is_git_project() is an internal helper with no public API surface; all callers are within commitizen/commands/. In the standard path (exit code 0, output "true\n"), the new code is semantically identical to the original one-liner at commitizen/git.py:316. is_staging_clean() and every other helper in commitizen/git.py are untouched. All five new tests plus every previously-existing is_git_project / is_staging_clean test in tests/test_git.py continue to pass. Checklist I have read the contributing guidelines Was generative AI tooling used to co-author this PR? Yes (please specify the tool below) Generated-by: Claude following the guidelines Code Changes Add test cases to all the changes you introduce Run uv run poe all locally to ensure this change passes linter check and tests Manually test the changes (see "Steps to Test" below) Update the documentation for the changes Documentation Changes is_git_project() is an internal helper with no user-facing documentation page. A full docstring explaining the exit-code-first logic and ANSI-strip rationale has been added to the function itself. Expected Behavior Scenario Outcome Inside a git work tree, clean subprocess output ("true\n") is_git_project() returns True — unchanged Outside any git repo (git rev-parse exits 128) is_git_project() returns False; --debug shows rc=128 and the fatal error text Inside a git work tree, output has ANSI colour prefix (e.g., "\x1b[0mtrue\r\n") is_git_project() returns True — regression fix for #1497 Inside .git of a bare repo (git rev-parse exits 0, output "false\n") is_git_project() returns False Output is a string containing "true" as a substring ("untrue", "nottrue") is_git_project() returns False Steps to Test This Pull Request git fetch fork fix/1497-better-not-a-git-project-diagnostics git checkout fork/fix/1497-better-not-a-git-project-diagnostics # 1. Targeted regression test. uv run pytest tests/test_git.py -k is_git_project -v # 2. Reproduce-the-bug-then-verify-the-fix sequence. # Simulate the ANSI-prefixed output that Git Bash on Windows injects before "true". python - <<'EOF' from unittest.mock import patch from commitizen import cmd, git # #1497 failure mode: shell wrapper prepends an ANSI SGR reset noisy = cmd.Command("\x1b[0mtrue\r\n", "", b"", b"", 0) with patch("commitizen.cmd.run", return_value=noisy): result = git.is_git_project() assert result is True, f"Expected True, got {result!r}" print("OK: ANSI-prefixed 'true' is accepted") # Defensive check: garbage substrings ending in "true" must still be rejected for bad in ("untrue", "nottrue", "test true false"): fake = cmd.Command(f"{bad}\n", "", b"", b"", 0) with patch("commitizen.cmd.run", return_value=fake): result = git.is_git_project() assert result is False, f"Expected False for {bad!r}, got {result!r}" print("OK: substring-'true' strings are all rejected") EOF Additional Context This fix was surfaced during the #1964 issue audit. The triage comment on #1497 identified commitizen/git.py:314–316 (master) as the likely culprit — the strict == "true" equality check fails when a shell wrapper injects ANSI colour codes into subprocess output, a documented behaviour of Git Bash on Windows when colour is enabled globally. Because the exact failure environment couldn't be reproduced locally, the new logger.debug path at both non-zero-exit and unexpected-output branches is the primary diagnostic improvement: it closes the feedback loop for any future reporter without requiring a code change.

Open Graph Description: Description Closes #1497. Why Users running commitizen via uv tool install commitizen inside Git Bash on Windows 11 encounter NotAGitProjectError even though running git rev-parse --is-inside-work-...

X Description: Description Closes #1497. Why Users running commitizen via uv tool install commitizen inside Git Bash on Windows 11 encounter NotAGitProjectError even though running git rev-parse --is-inside-work-...

Opengraph URL: https://github.com/commitizen-tools/commitizen/pull/1980

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:7010db99-0a0d-10c6-01f3-f9bb628e30d1
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idED8C:D3583:1038CEE:16A99B0:6A4DF4D4
html-safe-nonce926570488648e3671b4afd618aacb1a30d4c41f20a7dad8d23e3da039f675393
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDhDOkQzNTgzOjEwMzhDRUU6MTZBOTlCMDo2QTRERjRENCIsInZpc2l0b3JfaWQiOiI2OTYzMjkzNzg2MDMwNzA2NzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacfeb7061d138ef5ce1fa6d6d28d3341f9a1a6d70df9f1a870dff84c92edc060ef
hovercard-subject-tagpull_request:3654780217
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/commitizen-tools/commitizen/pull/1980/files
twitter:imagehttps://avatars.githubusercontent.com/u/26526132?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/26526132?s=400&v=4
og:image:altDescription Closes #1497. Why Users running commitizen via uv tool install commitizen inside Git Bash on Windows 11 encounter NotAGitProjectError even though running git rev-parse --is-inside-work-...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/commitizen-tools/commitizen git https://github.com/commitizen-tools/commitizen.git
octolytics-dimension-user_id62252524
octolytics-dimension-user_logincommitizen-tools
octolytics-dimension-repository_id106127589
octolytics-dimension-repository_nwocommitizen-tools/commitizen
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id106127589
octolytics-dimension-repository_network_root_nwocommitizen-tools/commitizen
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef4bb89367ca678f057d79b1abc45d6675b1bd5b2
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/commitizen-tools/commitizen/pull/1980/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcommitizen-tools%2Fcommitizen%2Fpull%2F1980%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcommitizen-tools%2Fcommitizen%2Fpull%2F1980%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=commitizen-tools%2Fcommitizen
Reloadhttps://github.com/commitizen-tools/commitizen/pull/1980/files
Reloadhttps://github.com/commitizen-tools/commitizen/pull/1980/files
Reloadhttps://github.com/commitizen-tools/commitizen/pull/1980/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1980/files
commitizen-tools https://github.com/commitizen-tools
commitizenhttps://github.com/commitizen-tools/commitizen
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1980/files
Notifications https://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen
Fork 343 https://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen
Star 3.5k https://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen
Code https://github.com/commitizen-tools/commitizen
Issues 116 https://github.com/commitizen-tools/commitizen/issues
Pull requests 45 https://github.com/commitizen-tools/commitizen/pulls
Discussions https://github.com/commitizen-tools/commitizen/discussions
Actions https://github.com/commitizen-tools/commitizen/actions
Projects https://github.com/commitizen-tools/commitizen/projects
Security and quality 0 https://github.com/commitizen-tools/commitizen/security
Insights https://github.com/commitizen-tools/commitizen/pulse
Code https://github.com/commitizen-tools/commitizen
Issues https://github.com/commitizen-tools/commitizen/issues
Pull requests https://github.com/commitizen-tools/commitizen/pulls
Discussions https://github.com/commitizen-tools/commitizen/discussions
Actions https://github.com/commitizen-tools/commitizen/actions
Projects https://github.com/commitizen-tools/commitizen/projects
Security and quality https://github.com/commitizen-tools/commitizen/security
Insights https://github.com/commitizen-tools/commitizen/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fcommitizen-tools%2Fcommitizen%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen%2Fissues%2Fnew%2Fchoose
bearomorphismhttps://github.com/bearomorphism
commitizen-tools:masterhttps://github.com/commitizen-tools/commitizen/tree/master
bearomorphism:fix/1497-better-not-a-git-project-diagnosticshttps://github.com/bearomorphism/commitizen/tree/fix/1497-better-not-a-git-project-diagnostics
Conversation 7 https://github.com/commitizen-tools/commitizen/pull/1980
Commits 2 https://github.com/commitizen-tools/commitizen/pull/1980/commits
Checks 20 https://github.com/commitizen-tools/commitizen/pull/1980/checks
Files changed https://github.com/commitizen-tools/commitizen/pull/1980/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1980/files
fix(git): tolerate noisy git rev-parse output in is_git_project https://github.com/commitizen-tools/commitizen/pull/1980/files#top
Show all changes 2 commits https://github.com/commitizen-tools/commitizen/pull/1980/files
ee91310 fix(git): tolerate noisy `git rev-parse` output in is_git_project bearomorphism May 9, 2026 https://github.com/commitizen-tools/commitizen/pull/1980/commits/ee91310e40bc90a12c2b2a3176a4291a171d3371
b03ce74 docs(test_git): correct is_git_project test docstrings bearomorphism May 9, 2026 https://github.com/commitizen-tools/commitizen/pull/1980/commits/b03ce747e4da68b285b917eef7e9496106530d30
Clear filters https://github.com/commitizen-tools/commitizen/pull/1980/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1980/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1980/files
git.py https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-2c36ae6439ace4898e030adb6f7a861fd8e5ae0002ca472cc97e627ea20b3d96
test_git.py https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-525635b43f5ec42f8b19fa010a1681f61b7832c76bccde68dc8e04c9f3c8de9b
commitizen/git.pyhttps://github.com/commitizen-tools/commitizen/pull/1980/files#diff-2c36ae6439ace4898e030adb6f7a861fd8e5ae0002ca472cc97e627ea20b3d96
View file https://github.com/commitizen-tools/commitizen/blob/b03ce747e4da68b285b917eef7e9496106530d30/commitizen/git.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/commitizen-tools/commitizen/pull/1980/{{ revealButtonHref }}
https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-2c36ae6439ace4898e030adb6f7a861fd8e5ae0002ca472cc97e627ea20b3d96
https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-2c36ae6439ace4898e030adb6f7a861fd8e5ae0002ca472cc97e627ea20b3d96
https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-2c36ae6439ace4898e030adb6f7a861fd8e5ae0002ca472cc97e627ea20b3d96
https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-2c36ae6439ace4898e030adb6f7a861fd8e5ae0002ca472cc97e627ea20b3d96
tests/test_git.pyhttps://github.com/commitizen-tools/commitizen/pull/1980/files#diff-525635b43f5ec42f8b19fa010a1681f61b7832c76bccde68dc8e04c9f3c8de9b
View file https://github.com/commitizen-tools/commitizen/blob/b03ce747e4da68b285b917eef7e9496106530d30/tests/test_git.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/commitizen-tools/commitizen/pull/1980/{{ revealButtonHref }}
https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-525635b43f5ec42f8b19fa010a1681f61b7832c76bccde68dc8e04c9f3c8de9b
https://github.com/commitizen-tools/commitizen/pull/1980/files#diff-525635b43f5ec42f8b19fa010a1681f61b7832c76bccde68dc8e04c9f3c8de9b
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1980/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.