diff --git a/aider/repo.py b/aider/repo.py index 92b5e3bf5b8..e4ced4ae3a1 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -123,6 +123,12 @@ def __init__( # https://github.com/gitpython-developers/GitPython/issues/427 self.repo = git.Repo(repo_paths.pop(), odbt=git.GitDB) + + if not self.repo.working_tree_dir: + raise FileNotFoundError( + "The git repo does not seem to have a working tree?" + ) + self.root = utils.safe_abs_path(self.repo.working_tree_dir) if aider_ignore_file: diff --git a/tests/basic/test_repo.py b/tests/basic/test_repo.py index 71ba9479830..610ea9631fb 100644 --- a/tests/basic/test_repo.py +++ b/tests/basic/test_repo.py @@ -714,3 +714,10 @@ def test_get_commit_message_uses_system_prompt_prefix(self, mock_send): system_msg_content.startswith(prefix), "system_prompt_prefix should be prepended to the system prompt", ) + + def test_bare_repo_raises_file_not_found(self): + with tempfile.TemporaryDirectory() as tmpdir: + bare_path = Path(tmpdir) / "bare.git" + git.Repo.init(str(bare_path), bare=True) + with self.assertRaises(FileNotFoundError): + GitRepo(InputOutput(), None, str(bare_path))