1
# Copyright (C) 2020 Jelmer Vernooij
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for breezy.branch.InterBranch.copy_content_into."""
19
from breezy import branch
20
from breezy.errors import NoSuchFile
21
from breezy.tests import TestNotApplicable
22
from breezy.tests.per_intertree import (
27
class TestFindPaths(TestCaseWithTwoTrees):
29
def test_path_missing(self):
30
tree1 = self.make_branch_and_tree('1')
31
tree2 = self.make_to_branch_and_tree('2')
32
self.build_tree_contents([
33
('1/file', b'apples'),
34
('2/file', b'apples'),
38
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
39
inter = self.intertree_class(tree1, tree2)
40
self.assertRaises(NoSuchFile, inter.find_source_path, 'missing')
41
self.assertRaises(NoSuchFile, inter.find_target_path, 'missing')
42
self.assertRaises(NoSuchFile, inter.find_source_paths, ['missing'])
43
self.assertRaises(NoSuchFile, inter.find_target_paths, ['missing'])
45
def test_old_path(self):
46
tree1 = self.make_branch_and_tree('1')
47
tree2 = self.make_to_branch_and_tree('2')
48
self.build_tree_contents([
49
('2/file', b'apples'),
52
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
53
inter = self.intertree_class(tree1, tree2)
54
self.assertIs(None, inter.find_source_path('file'))
55
self.assertEqual({'file': None}, inter.find_source_paths(['file']))
57
def test_new_path(self):
58
tree1 = self.make_branch_and_tree('1')
59
tree2 = self.make_to_branch_and_tree('2')
60
self.build_tree_contents([
61
('1/file', b'apples'),
64
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
65
inter = self.intertree_class(tree1, tree2)
66
self.assertIs(None, inter.find_target_path('file'))
67
self.assertEqual({'file': None}, inter.find_target_paths(['file']))
69
def test_unchanged(self):
70
tree1 = self.make_branch_and_tree('1')
71
self.build_tree_contents([
72
('1/file', b'apples'),
77
tree2 = self.make_to_branch_and_tree('2')
78
tree2.pull(tree1.branch)
79
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
80
inter = self.intertree_class(tree1, tree2)
81
self.assertEqual('file', inter.find_target_path('file'))
82
self.assertEqual({'file': 'file'}, inter.find_target_paths(['file']))
83
self.assertEqual('file', inter.find_source_path('file'))
84
self.assertEqual({'file': 'file'}, inter.find_source_paths(['file']))
86
def test_rename(self):
87
tree1 = self.make_branch_and_tree('1')
88
self.build_tree_contents([
89
('1/file', b'apples'),
94
tree2 = self.make_to_branch_and_tree('2')
95
tree2.pull(tree1.branch)
96
tree2.rename_one('file', 'newfile')
97
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
98
inter = self.intertree_class(tree1, tree2)
99
self.assertEqual('newfile', inter.find_target_path('file'))
100
self.assertEqual({'file': 'newfile'}, inter.find_target_paths(['file']))
101
self.assertEqual('file', inter.find_source_path('newfile'))
102
self.assertEqual({'newfile': 'file'}, inter.find_source_paths(['newfile']))
105
tree1 = self.make_branch_and_tree('1')
106
self.build_tree_contents([
107
('1/file', b'apples'),
112
tree2 = self.make_to_branch_and_tree('2')
113
tree2.pull(tree1.branch)
114
tree2.copy_one('file', 'newfile')
115
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
116
inter = self.intertree_class(tree1, tree2)
117
self.assertIn(inter.find_target_path('file'), ['file', 'newfile'])
118
self.assertIn(inter.find_source_path('newfile'), ['file', None])
119
self.assertEqual('file', inter.find_source_path('file'))
120
self.assertIn(inter.find_source_paths(['newfile']), [{'newfile': 'file'}, {'newfile': None}])
123
inter.find_source_paths(['newfile', 'file']), [
124
{'newfile': 'file', 'file': 'file'},
125
{'newfile': None, 'file': 'file'},