Only commit file that gpt edits, not other dirty files. Also ensure commit msg only depends on diffs from the GPT edited file.
(self)
| 610 | self.assertEqual(num_commits, 2) |
| 611 | |
| 612 | def test_only_commit_gpt_edited_file(self): |
| 613 | """ |
| 614 | Only commit file that gpt edits, not other dirty files. |
| 615 | Also ensure commit msg only depends on diffs from the GPT edited file. |
| 616 | """ |
| 617 | |
| 618 | with GitTemporaryDirectory(): |
| 619 | repo = git.Repo() |
| 620 | |
| 621 | fname1 = Path("file1.txt") |
| 622 | fname2 = Path("file2.txt") |
| 623 | |
| 624 | fname1.write_text("one\n") |
| 625 | fname2.write_text("two\n") |
| 626 | |
| 627 | repo.git.add(str(fname1)) |
| 628 | repo.git.add(str(fname2)) |
| 629 | repo.git.commit("-m", "new") |
| 630 | |
| 631 | # DIRTY! |
| 632 | fname1.write_text("ONE\n") |
| 633 | |
| 634 | io = InputOutput(yes=True) |
| 635 | coder = Coder.create(self.GPT35, "diff", io=io, fnames=[str(fname1), str(fname2)]) |
| 636 | |
| 637 | def mock_send(*args, **kwargs): |
| 638 | coder.partial_response_content = f""" |
| 639 | Do this: |
| 640 | |
| 641 | {str(fname2)} |
| 642 | <<<<<<< SEARCH |
| 643 | two |
| 644 | ======= |
| 645 | TWO |
| 646 | >>>>>>> REPLACE |
| 647 | |
| 648 | """ |
| 649 | coder.partial_response_function_call = dict() |
| 650 | return [] |
| 651 | |
| 652 | def mock_get_commit_message(diffs, context, user_language=None): |
| 653 | self.assertNotIn("one", diffs) |
| 654 | self.assertNotIn("ONE", diffs) |
| 655 | return "commit message" |
| 656 | |
| 657 | coder.send = mock_send |
| 658 | coder.repo.get_commit_message = MagicMock(side_effect=mock_get_commit_message) |
| 659 | |
| 660 | coder.run(with_message="hi") |
| 661 | |
| 662 | content = fname2.read_text() |
| 663 | self.assertEqual(content, "TWO\n") |
| 664 | |
| 665 | self.assertTrue(repo.is_dirty(path=str(fname1))) |
| 666 | |
| 667 | def test_gpt_edit_to_dirty_file(self): |
| 668 | """A dirty file should be committed before the GPT edits are committed""" |
nothing calls this directly
no test coverage detected