|
9 | 9 | from unittest import TestCase |
10 | 10 | from unittest.mock import MagicMock, patch |
11 | 11 |
|
12 | | -from templatron.exceptions import HookFailure |
| 12 | +from templatron.exceptions import HookFailure, StaleCloneError |
13 | 13 | from templatron.repo.repository import Repository |
14 | 14 | from templatron.repo.template import Template |
15 | 15 |
|
@@ -572,16 +572,36 @@ def test_switch_to_update_branch_fixing(self, mock_git): |
572 | 572 | mock_git.assert_not_called() |
573 | 573 |
|
574 | 574 | @patch.object(Repository, "update_branch_name", "fake_branch") |
| 575 | + @patch("templatron.repo.repository.Repository.local_branch_exists") |
575 | 576 | @patch("templatron.repo.repository.Repository.git_cmd") |
576 | | - def test_switch_to_update_branch_not_fixing(self, mock_git): |
| 577 | + def test_switch_to_update_branch_not_fixing(self, mock_git, mock_exists): |
577 | 578 | """ |
578 | 579 | Docs |
579 | 580 | """ |
580 | 581 |
|
| 582 | + mock_exists.return_value = False |
581 | 583 | self.test_repo.operation = "not fixing" |
582 | 584 | self.test_repo.switch_to_update_branch() |
583 | 585 | mock_git.assert_called_with("checkout", "-b", "fake_branch") |
584 | 586 |
|
| 587 | + @patch.object(Repository, "update_branch_name", "fake_branch") |
| 588 | + @patch("templatron.repo.repository.Repository.local_branch_exists") |
| 589 | + @patch("templatron.repo.repository.Repository.git_cmd") |
| 590 | + def test_switch_to_update_branch_stale_branch( |
| 591 | + self, mock_git, mock_exists |
| 592 | + ): |
| 593 | + """ |
| 594 | + Test switch_to_update_branch() raises StaleCloneError when the |
| 595 | + target update branch already exists locally — typically from a |
| 596 | + prior run that didn't clean up. |
| 597 | + """ |
| 598 | + |
| 599 | + mock_exists.return_value = True |
| 600 | + self.test_repo.operation = "not fixing" |
| 601 | + with self.assertRaisesRegex(StaleCloneError, "fake_branch"): |
| 602 | + self.test_repo.switch_to_update_branch() |
| 603 | + mock_git.assert_not_called() |
| 604 | + |
585 | 605 | @patch.object(Repository, "needs_update", True) |
586 | 606 | @patch("templatron.repo.repository.Repository.clean_stale_branches") |
587 | 607 | @patch("templatron.repo.repository.Repository.clone") |
|
0 commit comments