fix: handle paths outside repository - #5628
Conversation
|
Live check on main 5dc9490: aider/repo.py normalize_path does Path(self.root)/path then relative_to(self.root), which raises ValueError for an absolute path outside the repo. ignored_file already catches that (returns True). path_in_repo at 574 does not. is_dirty(path) calls path_in_repo first, so an outside path never reaches "untracked => dirty"; it crashes. PR head ef446b9 wraps normalize_path in path_in_repo, returns False on ValueError. is_dirty then returns True. TestPathOutsideRepoIsNotTracked uses Path.cwd().parent/"outside.txt" under GitTemporaryDirectory. That is the right pin. I would merge. Optional follow-up, not blocking: the same relative_to hole is still live in whatever other callers skip the try (abs_root_path does not use relative_to). |
) An image outside the repository is accepted by /read-only from anywhere. Promoting it with /add reaches GitRepo.path_in_repo() with an out-of-root absolute path, which raised ValueError on main and killed the session. With the path_in_repo() guard from this branch it is answered as 'not part of the repository' instead. Fails without the guard, passes with it.
test: pin /read-only + /add promotion of an outside image (Aider-AI#5620)Add regression coverage for /read-only followed by /add on an image outside the repository. Verify that the operation does not raise ValueError and that the image remains read-only rather than being added as an editable file. Test-only change; no production code changes. Related to Aider-AI#5620. For inclusion in Aider-AI#5628.
|
|
Fixes #5620
Summary
path_in_repo()and itsis_dirty(path)caller from propagatingValueErrorTests
pytest -q tests/basic/test_repo.py::TestRepo::test_path_outside_repo_is_not_trackedpytest -q tests/basic/test_repo.pypre-commit run --files aider/repo.py tests/basic/test_repo.py