Fix TypeError when working_tree_dir is None#4973
Open
zerone0x wants to merge 1 commit intoAider-AI:mainfrom
Open
Fix TypeError when working_tree_dir is None#4973zerone0x wants to merge 1 commit intoAider-AI:mainfrom
zerone0x wants to merge 1 commit intoAider-AI:mainfrom
Conversation
Guard against None value from repo.working_tree_dir in GitRepo.__init__ by raising FileNotFoundError before passing it to safe_abs_path. This prevents the uncaught TypeError when aider is run in a bare git repository. Fixes Aider-AI#4971 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Nonevalue fromrepo.working_tree_dirinGitRepo.__init__to preventTypeErrorworking_tree_dirisNone(e.g., bare repositories), raiseFileNotFoundErrorwith a descriptive message instead of crashing with an uncaughtTypeErrorinpathlib.pyContext
The crash occurs because
self.repo.working_tree_dirreturnsNonefor bare git repositories, and thisNonegets passed tosafe_abs_path()->Path(res).resolve(), which raisesTypeError.The fix raises
FileNotFoundErrorearly inGitRepo.__init__, which is already the expected exception type (caught inmain.pyline 921). The error message matches the existingsanity_check_repo()message for consistency.Test plan
test_bare_repo_raises_file_not_foundtesttests/basic/test_repo.pypassFixes #4971
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com