mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 21:34:59 +00:00
handle submodules (or other dirs) which are git tracked #336
This commit is contained in:
parent
5d0e92296a
commit
bf6cd8294e
3 changed files with 29 additions and 46 deletions
|
@ -728,6 +728,7 @@ class Coder:
|
|||
else:
|
||||
files = self.get_inchat_relative_files()
|
||||
|
||||
files = [fname for fname in files if Path(self.abs_root_path(fname)).is_file()]
|
||||
return sorted(set(files))
|
||||
|
||||
def get_all_abs_files(self):
|
||||
|
|
|
@ -146,6 +146,9 @@ class InputOutput:
|
|||
except FileNotFoundError:
|
||||
self.tool_error(f"{filename}: file not found error")
|
||||
return
|
||||
except IsADirectoryError:
|
||||
self.tool_error(f"{filename}: is a directory")
|
||||
return
|
||||
except UnicodeError as e:
|
||||
self.tool_error(f"{filename}: {e}")
|
||||
self.tool_error("Use --encoding to set the unicode encoding.")
|
||||
|
|
|
@ -122,33 +122,6 @@ class TestCoder(unittest.TestCase):
|
|||
fname.unlink()
|
||||
self.assertEqual(coder.get_last_modified(), 0)
|
||||
|
||||
def test_check_for_file_mentions(self):
|
||||
# Mock the IO object
|
||||
mock_io = MagicMock()
|
||||
|
||||
# Initialize the Coder object with the mocked IO and mocked repo
|
||||
coder = Coder.create(models.GPT4, None, mock_io)
|
||||
|
||||
# Mock the git repo
|
||||
mock = MagicMock()
|
||||
mock.return_value = set(["file1.txt", "file2.py"])
|
||||
coder.repo.get_tracked_files = mock
|
||||
|
||||
# Call the check_for_file_mentions method
|
||||
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
||||
|
||||
# Check if coder.abs_fnames contains both files
|
||||
expected_files = set(
|
||||
map(
|
||||
str,
|
||||
[
|
||||
Path(coder.root) / "file1.txt",
|
||||
Path(coder.root) / "file2.py",
|
||||
],
|
||||
)
|
||||
)
|
||||
self.assertEqual(coder.abs_fnames, expected_files)
|
||||
|
||||
def test_get_files_content(self):
|
||||
tempdir = Path(tempfile.mkdtemp())
|
||||
|
||||
|
@ -167,30 +140,36 @@ class TestCoder(unittest.TestCase):
|
|||
self.assertIn("file1.txt", content)
|
||||
self.assertIn("file2.txt", content)
|
||||
|
||||
def test_check_for_filename_mentions_of_longer_paths(self):
|
||||
# Mock the IO object
|
||||
def test_check_for_filename_mentions(self):
|
||||
with GitTemporaryDirectory():
|
||||
repo = git.Repo()
|
||||
|
||||
mock_io = MagicMock()
|
||||
|
||||
fname1 = Path("file1.txt")
|
||||
fname2 = Path("file2.py")
|
||||
|
||||
fname1.write_text("one\n")
|
||||
fname2.write_text("two\n")
|
||||
|
||||
repo.git.add(str(fname1))
|
||||
repo.git.add(str(fname2))
|
||||
repo.git.commit("-m", "new")
|
||||
|
||||
# Initialize the Coder object with the mocked IO and mocked repo
|
||||
coder = Coder.create(models.GPT4, None, mock_io)
|
||||
|
||||
mock = MagicMock()
|
||||
mock.return_value = set(["file1.txt", "file2.py"])
|
||||
coder.repo.get_tracked_files = mock
|
||||
|
||||
# Call the check_for_file_mentions method
|
||||
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
||||
|
||||
# Check if coder.abs_fnames contains both files
|
||||
expected_files = set(
|
||||
map(
|
||||
str,
|
||||
[
|
||||
Path(coder.root) / "file1.txt",
|
||||
Path(coder.root) / "file2.py",
|
||||
],
|
||||
)
|
||||
str(Path(coder.root) / fname1),
|
||||
str(Path(coder.root) / fname2),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEqual(coder.abs_fnames, expected_files)
|
||||
|
||||
def test_check_for_ambiguous_filename_mentions_of_longer_paths(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue