|
43 | 43 | from test.lib.fixtures import fixture_repo, read_only_fixture, writable_fixture |
44 | 44 |
|
45 | 45 |
|
| 46 | +@pytest.mark.parametrize( |
| 47 | + "branch_name", ["--pathspec-from-file=pathspecs", "-f", "--orphan=checkout-target", "-Bcheckout-target"] |
| 48 | +) |
| 49 | +def test_cloned_head_checkout_rejects_option_shaped_branch_names(branch_name): |
| 50 | + with fixture_repo("refs.sh", "unsafe-branch", "sha1", branch_name, write=True, subdir="clone") as cloned: |
| 51 | + branch = cloned.active_branch |
| 52 | + assert branch.name == branch_name |
| 53 | + commit = cloned.head.commit |
| 54 | + path = Path(cloned.working_tree_dir) / "file.txt" |
| 55 | + content = path.read_bytes() |
| 56 | + status = cloned.git.status("--porcelain") |
| 57 | + assert status.startswith(" M file.txt") |
| 58 | + for allow_unsafe_options in (False, True): |
| 59 | + with patch.object(Git, "execute", autospec=True, side_effect=Git.execute) as run: |
| 60 | + with pytest.raises(UnsafeOptionError) as error: |
| 61 | + branch.checkout(force=False, allow_unsafe_options=allow_unsafe_options) |
| 62 | + run.assert_not_called() |
| 63 | + assert "unmatched-private-content" not in str(error.value) |
| 64 | + assert cloned.active_branch == branch |
| 65 | + assert cloned.head.commit == commit |
| 66 | + assert path.read_bytes() == content |
| 67 | + assert cloned.git.status("--porcelain") == status |
| 68 | + |
| 69 | + |
46 | 70 | @pytest.mark.parametrize("object_format", ["sha1", "sha256"]) |
47 | 71 | def test_reference_names_preserve_unicode_line_separators(object_format): |
48 | 72 | names = [ |
@@ -658,16 +682,6 @@ def test_head_checkout_rejects_pathspec_from_file(self, rw_repo): |
658 | 682 | with self.assertRaises(UnsafeOptionError): |
659 | 683 | branch.checkout() |
660 | 684 |
|
661 | | - def test_cloned_head_checkout_rejects_pathspec_from_file(self): |
662 | | - with fixture_repo("refs.sh", "unsafe-branch", write=True, subdir="clone") as cloned: |
663 | | - branch_name = "--pathspec-from-file=pathspecs" |
664 | | - assert cloned.active_branch.name == branch_name |
665 | | - for allow_unsafe_options in (False, True): |
666 | | - with self.assertRaises(UnsafeOptionError) as error: |
667 | | - cloned.active_branch.checkout(allow_unsafe_options=allow_unsafe_options) |
668 | | - assert "unmatched-private-content" not in str(error.exception) |
669 | | - assert cloned.active_branch.name == branch_name |
670 | | - |
671 | 685 | @with_rw_repo("HEAD") |
672 | 686 | def test_head_reset_rejects_pathspec_from_file(self, rw_repo): |
673 | 687 | pathspecs = read_only_fixture("refs-input.sh") / "pathspecs" |
|
0 commit comments