This tests git.worktree_add, git.is_worktree, git.worktree_rm, and git.worktree_prune. Tests for 'git worktree list' are covered in tests.unit.modules.git_test.
(self)
| 872 | ) |
| 873 | @pytest.mark.slow_test |
| 874 | def test_worktree_add_rm(self): |
| 875 | """ |
| 876 | This tests git.worktree_add, git.is_worktree, git.worktree_rm, and |
| 877 | git.worktree_prune. Tests for 'git worktree list' are covered in |
| 878 | tests.unit.modules.git_test. |
| 879 | """ |
| 880 | # We don't need to enclose this comparison in a try/except, since the |
| 881 | # decorator would skip this test if git is not installed and we'd never |
| 882 | # get here in the first place. |
| 883 | git_version = _git_version() |
| 884 | if git_version >= LooseVersion("2.6.0"): |
| 885 | worktree_add_prefix = "Preparing " |
| 886 | else: |
| 887 | worktree_add_prefix = "Enter " |
| 888 | |
| 889 | worktree_path = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) |
| 890 | worktree_basename = os.path.basename(worktree_path) |
| 891 | worktree_path2 = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) |
| 892 | worktree_basename2 = os.path.basename(worktree_path2) |
| 893 | |
| 894 | # Even though this is Windows, git commands return a unix style path |
| 895 | if salt.utils.platform.is_windows(): |
| 896 | worktree_path = worktree_path.replace("\\", "/") |
| 897 | worktree_path2 = worktree_path2.replace("\\", "/") |
| 898 | |
| 899 | # Add the worktrees |
| 900 | ret = self.run_function( |
| 901 | "git.worktree_add", |
| 902 | [self.repo, worktree_path], |
| 903 | ) |
| 904 | self.assertTrue(worktree_add_prefix in ret) |
| 905 | self.assertTrue(worktree_basename in ret) |
| 906 | ret = self.run_function("git.worktree_add", [self.repo, worktree_path2]) |
| 907 | self.assertTrue(worktree_add_prefix in ret) |
| 908 | self.assertTrue(worktree_basename2 in ret) |
| 909 | # Check if this new path is a worktree |
| 910 | self.assertTrue(self.run_function("git.is_worktree", [worktree_path])) |
| 911 | # Check if the main repo is a worktree |
| 912 | self.assertFalse(self.run_function("git.is_worktree", [self.repo])) |
| 913 | # Check if a non-repo directory is a worktree |
| 914 | empty_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) |
| 915 | self.assertFalse(self.run_function("git.is_worktree", [empty_dir])) |
| 916 | shutil.rmtree(empty_dir) |
| 917 | # Remove the first worktree |
| 918 | self.assertTrue(self.run_function("git.worktree_rm", [worktree_path])) |
| 919 | # Prune the worktrees |
| 920 | prune_message = ( |
| 921 | "Removing worktrees/{}: gitdir file points to non-existent location".format( |
| 922 | worktree_basename |
| 923 | ) |
| 924 | ) |
| 925 | # Test dry run output. It should match the same output we get when we |
| 926 | # actually prune the worktrees. |
| 927 | result = self.run_function("git.worktree_prune", [self.repo], dry_run=True) |
| 928 | self.assertEqual(result, prune_message) |
| 929 | # Test pruning for real, and make sure the output is the same |
| 930 | self.assertEqual( |
| 931 | self.run_function("git.worktree_prune", [self.repo]), prune_message |
nothing calls this directly
no test coverage detected