Test that git_commit_verify controls whether --no-verify is passed to git commit
(self)
| 641 | |
| 642 | @unittest.skipIf(platform.system() == "Windows", "Git hook execution differs on Windows") |
| 643 | def test_git_commit_verify(self): |
| 644 | """Test that git_commit_verify controls whether --no-verify is passed to git commit""" |
| 645 | with GitTemporaryDirectory(): |
| 646 | # Create a new repo |
| 647 | raw_repo = git.Repo() |
| 648 | |
| 649 | # Create a file to commit |
| 650 | fname = Path("test_file.txt") |
| 651 | fname.write_text("initial content") |
| 652 | raw_repo.git.add(str(fname)) |
| 653 | |
| 654 | # Do the initial commit |
| 655 | raw_repo.git.commit("-m", "Initial commit") |
| 656 | |
| 657 | # Now create a pre-commit hook that always fails |
| 658 | hooks_dir = Path(raw_repo.git_dir) / "hooks" |
| 659 | hooks_dir.mkdir(exist_ok=True) |
| 660 | |
| 661 | pre_commit_hook = hooks_dir / "pre-commit" |
| 662 | pre_commit_hook.write_text("#!/bin/sh\nexit 1\n") # Always fail |
| 663 | pre_commit_hook.chmod(0o755) # Make executable |
| 664 | |
| 665 | # Modify the file |
| 666 | fname.write_text("modified content") |
| 667 | |
| 668 | # Create GitRepo with verify=True (default) |
| 669 | io = InputOutput() |
| 670 | git_repo_verify = GitRepo(io, None, None, git_commit_verify=True) |
| 671 | |
| 672 | # Attempt to commit - should fail due to pre-commit hook |
| 673 | commit_result = git_repo_verify.commit(fnames=[str(fname)], message="Should fail") |
| 674 | self.assertIsNone(commit_result) |
| 675 | |
| 676 | # Create GitRepo with verify=False |
| 677 | git_repo_no_verify = GitRepo(io, None, None, git_commit_verify=False) |
| 678 | |
| 679 | # Attempt to commit - should succeed by bypassing the hook |
| 680 | commit_result = git_repo_no_verify.commit(fnames=[str(fname)], message="Should succeed") |
| 681 | self.assertIsNotNone(commit_result) |
| 682 | |
| 683 | # Verify the commit was actually made |
| 684 | latest_commit_msg = raw_repo.head.commit.message |
| 685 | self.assertEqual(latest_commit_msg.strip(), "Should succeed") |
| 686 | |
| 687 | @patch("aider.models.Model.simple_send_with_retries") |
| 688 | def test_get_commit_message_uses_system_prompt_prefix(self, mock_send): |
nothing calls this directly
no test coverage detected