mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
test_gpt_edit_to_dirty_file
This commit is contained in:
parent
93795c085a
commit
95fb55b9d9
1 changed files with 48 additions and 0 deletions
|
@ -465,6 +465,54 @@ TWO
|
|||
|
||||
self.assertTrue(repo.is_dirty(path=str(fname1)))
|
||||
|
||||
def test_gpt_edit_to_dirty_file(self):
|
||||
"""A dirty file should be committed before the GPT edits are committed"""
|
||||
|
||||
with GitTemporaryDirectory():
|
||||
repo = git.Repo()
|
||||
|
||||
fname = Path("file.txt")
|
||||
fname.write_text("one\n")
|
||||
repo.git.add(str(fname))
|
||||
repo.git.commit("-m", "new")
|
||||
|
||||
fname.write_text("two\n")
|
||||
|
||||
io = InputOutput(yes=True)
|
||||
coder = Coder.create(models.GPT4, "diff", io=io, fnames=[str(fname)])
|
||||
|
||||
def mock_send(*args, **kwargs):
|
||||
coder.partial_response_content = f"""
|
||||
Do this:
|
||||
|
||||
{str(fname)}
|
||||
<<<<<<< HEAD
|
||||
two
|
||||
=======
|
||||
three
|
||||
>>>>>>> updated
|
||||
|
||||
"""
|
||||
coder.partial_response_function_call = dict()
|
||||
|
||||
coder.send = MagicMock(side_effect=mock_send)
|
||||
coder.repo.get_commit_message = MagicMock()
|
||||
coder.repo.get_commit_message.return_value = "commit message"
|
||||
|
||||
coder.run(with_message="hi")
|
||||
|
||||
content = fname.read_text()
|
||||
self.assertEqual(content, "three\n")
|
||||
|
||||
num_commits = len(list(repo.iter_commits(repo.active_branch.name)))
|
||||
self.assertEqual(num_commits, 3)
|
||||
|
||||
self.assertIn("two", repo.git.diff(["HEAD~1", "HEAD"]))
|
||||
self.assertIn("three", repo.git.diff(["HEAD~1", "HEAD"]))
|
||||
|
||||
self.assertIn("one", repo.git.diff(["HEAD~2", "HEAD~1"]))
|
||||
self.assertIn("two", repo.git.diff(["HEAD~2", "HEAD~1"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue