mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 22:04: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:
|
else:
|
||||||
files = self.get_inchat_relative_files()
|
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))
|
return sorted(set(files))
|
||||||
|
|
||||||
def get_all_abs_files(self):
|
def get_all_abs_files(self):
|
||||||
|
|
|
@ -146,6 +146,9 @@ class InputOutput:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.tool_error(f"{filename}: file not found error")
|
self.tool_error(f"{filename}: file not found error")
|
||||||
return
|
return
|
||||||
|
except IsADirectoryError:
|
||||||
|
self.tool_error(f"{filename}: is a directory")
|
||||||
|
return
|
||||||
except UnicodeError as e:
|
except UnicodeError as e:
|
||||||
self.tool_error(f"{filename}: {e}")
|
self.tool_error(f"{filename}: {e}")
|
||||||
self.tool_error("Use --encoding to set the unicode encoding.")
|
self.tool_error("Use --encoding to set the unicode encoding.")
|
||||||
|
|
|
@ -122,33 +122,6 @@ class TestCoder(unittest.TestCase):
|
||||||
fname.unlink()
|
fname.unlink()
|
||||||
self.assertEqual(coder.get_last_modified(), 0)
|
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):
|
def test_get_files_content(self):
|
||||||
tempdir = Path(tempfile.mkdtemp())
|
tempdir = Path(tempfile.mkdtemp())
|
||||||
|
|
||||||
|
@ -167,31 +140,37 @@ class TestCoder(unittest.TestCase):
|
||||||
self.assertIn("file1.txt", content)
|
self.assertIn("file1.txt", content)
|
||||||
self.assertIn("file2.txt", content)
|
self.assertIn("file2.txt", content)
|
||||||
|
|
||||||
def test_check_for_filename_mentions_of_longer_paths(self):
|
def test_check_for_filename_mentions(self):
|
||||||
# Mock the IO object
|
with GitTemporaryDirectory():
|
||||||
mock_io = MagicMock()
|
repo = git.Repo()
|
||||||
|
|
||||||
# Initialize the Coder object with the mocked IO and mocked repo
|
mock_io = MagicMock()
|
||||||
coder = Coder.create(models.GPT4, None, mock_io)
|
|
||||||
|
|
||||||
mock = MagicMock()
|
fname1 = Path("file1.txt")
|
||||||
mock.return_value = set(["file1.txt", "file2.py"])
|
fname2 = Path("file2.py")
|
||||||
coder.repo.get_tracked_files = mock
|
|
||||||
|
|
||||||
# Call the check_for_file_mentions method
|
fname1.write_text("one\n")
|
||||||
coder.check_for_file_mentions("Please check file1.txt and file2.py")
|
fname2.write_text("two\n")
|
||||||
|
|
||||||
# Check if coder.abs_fnames contains both files
|
repo.git.add(str(fname1))
|
||||||
expected_files = set(
|
repo.git.add(str(fname2))
|
||||||
map(
|
repo.git.commit("-m", "new")
|
||||||
str,
|
|
||||||
|
# Initialize the Coder object with the mocked IO and mocked repo
|
||||||
|
coder = Coder.create(models.GPT4, None, mock_io)
|
||||||
|
|
||||||
|
# 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(
|
||||||
[
|
[
|
||||||
Path(coder.root) / "file1.txt",
|
str(Path(coder.root) / fname1),
|
||||||
Path(coder.root) / "file2.py",
|
str(Path(coder.root) / fname2),
|
||||||
],
|
]
|
||||||
)
|
)
|
||||||
)
|
|
||||||
self.assertEqual(coder.abs_fnames, expected_files)
|
self.assertEqual(coder.abs_fnames, expected_files)
|
||||||
|
|
||||||
def test_check_for_ambiguous_filename_mentions_of_longer_paths(self):
|
def test_check_for_ambiguous_filename_mentions_of_longer_paths(self):
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue