diff --git a/aider/repo.py b/aider/repo.py index 040f8156b..07a47592c 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -50,9 +50,9 @@ class GitRepo: self.root = utils.safe_abs_path(self.repo.working_tree_dir) def add_new_files(self, fnames): - cur_files = [Path(fn).resolve() for fn in self.get_tracked_files()] + cur_files = [str(Path(fn).resolve()) for fn in self.get_tracked_files()] for fname in fnames: - if Path(fname).resolve() in cur_files: + if str(Path(fname).resolve()) in cur_files: continue if not Path(fname).exists(): continue @@ -183,7 +183,10 @@ class GitRepo: files.extend(staged_files) # convert to appropriate os.sep, since git always normalizes to / - res = set(str(Path(PurePosixPath(path))) for path in files) + res = set( + str(Path(PurePosixPath((Path(self.root) / path).relative_to(self.root)))) + for path in files + ) return res diff --git a/tests/test_repo.py b/tests/test_repo.py index 8451ec309..aee78abdf 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -170,3 +170,27 @@ class TestRepo(unittest.TestCase): fnames = git_repo.get_tracked_files() self.assertIn(str(fname), fnames) self.assertIn(str(fname2), fnames) + + def test_get_tracked_files_from_subdir(self): + with GitTemporaryDirectory(): + # new repo + raw_repo = git.Repo() + + # add it, but no commits at all in the raw_repo yet + fname = Path("subdir/new.txt") + fname.parent.mkdir() + fname.touch() + raw_repo.git.add(str(fname)) + + os.chdir(fname.parent) + + git_repo = GitRepo(InputOutput(), None, None) + + # better be there + fnames = git_repo.get_tracked_files() + self.assertIn(str(fname), fnames) + + # commit it, better still be there + raw_repo.git.commit("-m", "new") + fnames = git_repo.get_tracked_files() + self.assertIn(str(fname), fnames)