Skip to content

Fix | Report git errors instead of crashing, clear error outside a project - #359

Merged
diego-ojeda-binbash merged 1 commit into
masterfrom
fix/get-root-path-git-errors
Nov 15, 2026
Merged

diego-ojeda-binbash merged 1 commit into
masterfrom
fix/get-root-path-git-errors

Conversation

@diego-ojeda-binbash

Copy link
Copy Markdown
Contributor

What?

Case Before After
Repository owned by another user ("dubious ownership": Docker volumes, WSL) TypeError on every command except --help Exit 1 with git's message, including its git config --global --add safe.directory ... hint
git in another language, outside a repository The translated message didn't match, get_root_path returned None Recognized as "not a repository": git runs with LC_ALL=C
Outside a repository: tofu, terraform, kubectl, tfautomv AttributeError: 'NoneType' object has no attribute 'tf_binary' Exit 1: "Out of Leverage project context. Please cd into a Leverage project directory first."
Outside a repository: --version, tofu --help, run Worked Still work

How?

  1. get_root_path (leverage/path.py): forces LC_ALL=C. Any other git error becomes an ExitError with git's stderr; it never returns None anymore. The import-time fallbacks (get_project_root_or_current_dir_path, PROJECT_COMMON_TFVARS in credentials.py) catch that error instead of the TypeError workaround from [229] Fix issue with --version option #256. That workaround was this same bug, reported in Bug | leverage --version fails when OS locale is not english #229 for git in Spanish.
  2. State.paths (leverage/_internals.py): raises the "Out of Leverage project context" error when no project was found, at the moment a command asks for the paths. It's not raised from the leverage callback because click runs that callback before parsing the subcommand's --help, so leverage tofu --help outside a repository would break. credentials uses the new State.has_paths for its bootstrap check.
  3. Tests:

Results

  • 330 tests pass. Coverage: 77.28% → 78.03%.
  • Against the current code, the 7 new tests fail.

Not related, not touched: leverage aws configure list ends with an aws usage error, on master too. The configure wrapper seems to pass list without configure.

Closes #356

🤖 Generated with Claude Code

…oject

- get_root_path runs git with LC_ALL=C, so "not a git repository" is
  recognized in any locale (#229), and turns any other git error (e.g.
  dubious ownership) into an ExitError with git's message instead of
  returning None, which made every command crash with a TypeError
- The import-time fallbacks catch that ExitError instead of TypeError
  (the workaround from #256); the command reports it when it loads the
  configuration
- State.paths raises "Out of Leverage project context" when no project
  was found, so tofu/terraform/kubectl/tfautomv fail with that message
  instead of an AttributeError. Commands that work anywhere (--version,
  --help, run) are unaffected

Closes #356

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@diego-ojeda-binbash diego-ojeda-binbash added bug Something isn't working test labels Nov 15, 2026
@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 753df692-2961-4471-ba39-c5efb7a872dd
Commits

Reviewing files that changed from the base of the PR and between c8f0c79 and b2082a0.

Files selected for processing: 6

  • leverage/_internals.py
  • leverage/leverage.py
  • leverage/modules/credentials.py
  • leverage/path.py
  • tests/test_path.py
  • tests/test_root_path.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@diego-ojeda-binbash diego-ojeda-binbash self-assigned this Nov 15, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 43722610415

Coverage increased (+0.8%) to 78.034%

Details

  • Coverage increased (+0.8%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (21 of 22 lines covered, 95.45%).
  • 71 coverage regressions across 4 files.

Uncovered Changes

File Changed Covered %
leverage/modules/credentials.py 2 1 50.0%
Total (3 files) 22 21 95.45%

Coverage Regressions

71 previously-covered lines in 4 files lost coverage.

File Lines Losing Coverage Coverage
modules/credentials.py 55 62.74%
path.py 14 85.19%
leverage/modules/credentials.py 1 62.74%
leverage.py 1 91.11%

Coverage Stats

Coverage Status
Relevant Lines: 4128
Covered Lines: 3340
Line Coverage: 80.91%
Relevant Branches: 1080
Covered Branches: 724
Branch Coverage: 67.04%
Branches in Coverage %: Yes
Coverage Strength: 0.81 hits per line

💛 - Coveralls

@diego-ojeda-binbash
diego-ojeda-binbash merged commit 8be663f into master Nov 15, 2026
26 of 28 checks passed
@diego-ojeda-binbash
diego-ojeda-binbash deleted the fix/get-root-path-git-errors branch November 15, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug | Any git error other than "not a git repository" makes every command crash with a TypeError

3 participants