Repository navigation
fix: exit 2 when git cannot read the repository - #654
Conversation
Outside a repository, or in one git refuses for dubious ownership (a mounted checkout in a container, say), every git call failed and each check read that as nothing to check. The run reported every check as skipped and exited 0, so CI went green having checked nothing; --rev already exited 2 in the same place. When a requested check has to read git, ask git once whether it can and, if not, print its reason and exit 2. A message file, a piped message and a piped branch or author still need no repository, and a repository with no commits is still readable.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 55 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #654 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 2429 2456 +27
Branches 470 477 +7
=========================================
+ Hits 2429 2456 +27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 10.76%3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|



Summary
Sometimes git can't read the directory at all: it isn't a repository, or git rejects it for "dubious ownership". That second case is common when a checkout is mounted into a container or runs on a Jenkins or self-hosted agent. Every git call then fails, and each check took that to mean there was nothing to check. The run listed every check as skipped and exited 0, so CI went green without checking anything. In the same place,
--revalready exited 2.Now, when a requested check needs git, the CLI first asks git once whether it can read the repository. If git can't, the CLI prints git's own reason (which includes the
safe.directoryhint for dubious ownership) and exits 2, the same code the CLI uses for a broken setup.These still work without a repository:
-m msg.txt,echo … | commit-check -m)Before vs after
Before (2.19.4):
After:
-m,-b,-n,-e,-t,-f,--no-force-pushin a directory git refuses--rev HEADoutside a repository--rev 'HEAD' does not resolve, exit 2-m msg.txt, or a piped message, outside a repositoryecho bad_branch | commit-check -boutside a repositoryChanges
commit_check/util.py:git_repository_error()runsgit rev-parse --git-dirand returns git's message, orNonewhen git can read the repository.commit_check/main.py:_reads_repository()decides whether the requested checks need git. If they do and git can't read the repository, the CLI exits 2 with git's reason.--revruns the same check before resolving the revision. The--helpexit-code text mentions this case.README.md: the exit-code line covers it too.-b, and the helper's four outcomes.Testing
pytest: 1464 pass. The one failure,test_load_config_file_permission_error, happens only because the tests ran as root locally. It is unrelated.ruff check/ruff format --checkare clean.nobody, run as root (dubious ownership), and/tmp(not a repository).