mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
get tracked files by traversing the tree
This commit is contained in:
parent
73f5fb05e5
commit
68c26a60ef
2 changed files with 20 additions and 13 deletions
|
@ -971,8 +971,15 @@ class Coder:
|
||||||
if not self.repo:
|
if not self.repo:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
files = self.repo.git.execute(["git", "-c", "core.quotepath=off", "ls-files"])
|
try:
|
||||||
files = set(files.splitlines())
|
commit = self.repo.head.commit
|
||||||
|
except ValueError:
|
||||||
|
return set()
|
||||||
|
|
||||||
|
files = []
|
||||||
|
for blob in commit.tree.traverse():
|
||||||
|
if blob.type == "blob": # blob is a file
|
||||||
|
files.append(blob.path)
|
||||||
|
|
||||||
# convert to appropriate os.sep, since git always normalizes to /
|
# 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))) for path in files)
|
||||||
|
|
|
@ -30,9 +30,9 @@ class TestCoder(unittest.TestCase):
|
||||||
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
||||||
|
|
||||||
# Mock the git repo
|
# Mock the git repo
|
||||||
mock_repo = MagicMock()
|
mock = MagicMock()
|
||||||
mock_repo.git.execute.return_value = "file1.txt\nfile2.py"
|
mock.return_value = set(["file1.txt", "file2.py"])
|
||||||
coder.repo = mock_repo
|
coder.get_tracked_files = mock
|
||||||
|
|
||||||
# Call the check_for_file_mentions method
|
# Call the check_for_file_mentions method
|
||||||
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
||||||
|
@ -76,10 +76,9 @@ class TestCoder(unittest.TestCase):
|
||||||
# Initialize the Coder object with the mocked IO and mocked repo
|
# Initialize the Coder object with the mocked IO and mocked repo
|
||||||
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
||||||
|
|
||||||
# Mock the git repo
|
mock = MagicMock()
|
||||||
mock_repo = MagicMock()
|
mock.return_value = set(["file1.txt", "file2.py"])
|
||||||
mock_repo.git.execute.return_value = "file1.txt\nfile2.py"
|
coder.get_tracked_files = mock
|
||||||
coder.repo = mock_repo
|
|
||||||
|
|
||||||
# Call the check_for_file_mentions method
|
# Call the check_for_file_mentions method
|
||||||
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
||||||
|
@ -103,10 +102,9 @@ class TestCoder(unittest.TestCase):
|
||||||
# Initialize the Coder object with the mocked IO and mocked repo
|
# Initialize the Coder object with the mocked IO and mocked repo
|
||||||
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
coder = Coder.create(models.GPT4, None, mock_io, openai_api_key="fake_key")
|
||||||
|
|
||||||
# Mock the git repo
|
mock = MagicMock()
|
||||||
mock_repo = MagicMock()
|
mock.return_value = set(["file1.txt", "other/file1.txt"])
|
||||||
mock_repo.git.execute.return_value = "file1.txt\nother/file1.txt"
|
coder.get_tracked_files = mock
|
||||||
coder.repo = mock_repo
|
|
||||||
|
|
||||||
# Call the check_for_file_mentions method
|
# Call the check_for_file_mentions method
|
||||||
coder.check_for_file_mentions("Please check file1.txt!")
|
coder.check_for_file_mentions("Please check file1.txt!")
|
||||||
|
@ -376,6 +374,8 @@ class TestCoder(unittest.TestCase):
|
||||||
file_path.touch()
|
file_path.touch()
|
||||||
repo.git.add(str(file_path))
|
repo.git.add(str(file_path))
|
||||||
|
|
||||||
|
repo.git.commit("-m", "added")
|
||||||
|
|
||||||
# Create a Coder object on the temporary directory
|
# Create a Coder object on the temporary directory
|
||||||
coder = Coder.create(
|
coder = Coder.create(
|
||||||
models.GPT4,
|
models.GPT4,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue