1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
# test_bzrtools_import.py -- Testsuite for bzrtool's import code
# Copyright (C) 2010 James Westby <jw+debian@jameswestby.net>
#
# This file is part of bzr-builddeb.
#
# bzr-builddeb is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bzr-builddeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bzr-builddeb; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
from breezy.tests.scenarios import (
load_tests_apply_scenarios,
multiply_scenarios,
)
from ..bzrtools_import import import_dir
from .. import tests
load_tests = load_tests_apply_scenarios
class ImportArchiveTests(tests.TestCaseWithTransport):
scenarios = multiply_scenarios([
('git', dict(_format='git')),
('bzr', dict(_format='bzr'))])
def make_branch_and_tree(self, path):
return super().make_branch_and_tree(
path, format=self._format)
def test_strips_common_prefix(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
self.build_tree(["source/", "source/a/", "source/a/a", "source/a/b"])
import_dir(tree, "source")
self.assertEqual({'', 'a/a', 'a', 'a/b'}, tree.all_versioned_paths())
if tree.supports_setting_file_ids():
self.assertEqual(
["", "a", "a/a", "a/b"],
sorted([tree.id2path(i) for i in tree.all_file_ids()]))
def _add(self, tree, ps, fids=None):
if tree.supports_setting_file_ids():
tree.add(ps, ids=fids)
else:
tree.add(ps)
def test_removes_files(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.build_tree(["a", "b"])
self._add(tree, ["a", "b"])
self.addCleanup(tree.unlock)
self.build_tree(["source/", "source/a"])
import_dir(tree, "source")
self.assertEqual({'', 'a'}, tree.all_versioned_paths())
if tree.supports_setting_file_ids():
self.assertEqual(
["", "a"],
sorted([tree.id2path(i) for i in tree.all_file_ids()]))
def test_takes_file_id_from_another_tree(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
self.build_tree(["fileids/a"])
self._add(file_ids_tree, ["a"], [b"a-id"])
self.build_tree(["source/", "source/a"])
import_dir(tree, "source", file_ids_from=[file_ids_tree])
if tree.supports_setting_file_ids():
self.assertEqual(b"a-id", tree.path2id("a"))
def test_takes_file_id_from_first_of_several_trees(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
file_ids_tree2 = self.make_branch_and_tree("fileids2")
self.build_tree(["fileids/a", "fileids2/a"])
self._add(file_ids_tree, ["a"], [b"a-id"])
self._add(file_ids_tree2, ["a"], [b"other-a-id"])
self.build_tree(["source/", "source/a"])
import_dir(
tree, "source", file_ids_from=[file_ids_tree, file_ids_tree2])
if tree.supports_setting_file_ids():
self.assertEqual(b"a-id", tree.path2id("a"))
def test_takes_file_ids_from_last_of_several_trees_if_needed(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
file_ids_tree2 = self.make_branch_and_tree("fileids2")
self.build_tree(["fileids/b", "fileids2/a"])
self._add(file_ids_tree, ["b"], [b"b-id"])
self._add(file_ids_tree2, ["a"], [b"other-a-id"])
self.build_tree(["source/", "source/a"])
import_dir(
tree, "source", file_ids_from=[file_ids_tree, file_ids_tree2])
if tree.supports_setting_file_ids():
self.assertEqual(b"other-a-id", tree.path2id("a"))
def test_takes_file_id_from_target_tree(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
file_ids_tree2 = self.make_branch_and_tree("fileids2")
self.build_tree(["fileids/a", "fileids2/a"])
self._add(file_ids_tree, ["a"], [b"a-id"])
self._add(file_ids_tree2, ["a"], [b"other-a-id"])
self.build_tree(["source/", "source/a"])
import_dir(
tree, "source", file_ids_from=[file_ids_tree2],
target_tree=file_ids_tree)
if tree.supports_setting_file_ids():
self.assertEqual(b"a-id", tree.path2id("a"))
def test_leaves_file_id_of_existing_file(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.build_tree(["a"])
self._add(tree, ["a"], [b"a-id"])
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
self.build_tree(["fileids/a"])
self._add(file_ids_tree, ["a"], [b"other-a-id"])
self.build_tree(["source/", "source/a"])
import_dir(tree, "source", file_ids_from=[file_ids_tree])
if tree.supports_setting_file_ids():
self.assertEqual(b"a-id", tree.path2id("a"))
def test_replaces_file_id_of_existing_file_with_target_tree(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.build_tree(["a"])
self._add(tree, ["a"], [b"a-id"])
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
self.build_tree(["fileids/a"])
self._add(file_ids_tree, ["a"], [b"other-a-id"])
self.build_tree(["source/", "source/a"])
import_dir(tree, "source", target_tree=file_ids_tree)
if tree.supports_setting_file_ids():
self.assertEqual(b"other-a-id", tree.path2id("a"))
def test_rename_of_file_in_target_tree(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.build_tree(["a"])
self._add(tree, ["a"], [b"a-id"])
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
self.build_tree(["fileids/a", "fileids/b"])
# We give b the same id as a above, to simulate a rename
self._add(file_ids_tree, ["a", "b"], [b"other-a-id", b"a-id"])
self.build_tree(["source/", "source/a", "source/b"])
import_dir(tree, "source", target_tree=file_ids_tree)
if tree.supports_setting_file_ids():
self.assertEqual(b"other-a-id", tree.path2id("a"))
self.assertEqual(b"a-id", tree.path2id("b"))
def test_rename_of_file_in_target_tree_with_unversioned_replacement(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.build_tree(["a"])
self._add(tree, ["a"], [b"a-id"])
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
self.build_tree(["fileids/b"])
# We give b the same id as a above, to simulate a rename
self._add(file_ids_tree, ["b"], [b"a-id"])
# We continue to put "a" in the source, even though we didn't
# put it in file_ids_tree
self.build_tree(["source/", "source/a", "source/b"])
import_dir(tree, "source", target_tree=file_ids_tree)
if tree.supports_setting_file_ids():
self.assertEqual(b"a-id", tree.path2id("b"))
# a should get a random file id, so we just check the obvious
# things it shouldn't be
self.assertNotEqual(b"a-id", tree.path2id("a"))
self.assertNotEqual(None, tree.path2id("a"))
def test_dir_rename_in_target_tree(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.build_tree(["a/", "a/b"])
self._add(tree, ["a", "a/b"], [b"a-id", b"b-id"])
self.addCleanup(tree.unlock)
file_ids_tree = self.make_branch_and_tree("fileids")
self.build_tree(["fileids/b/", "fileids/b/b"])
# We give b the same id as a above, to simulate a rename
self._add(file_ids_tree, ["b", "b/b"], [b"a-id", b"b-id"])
self.build_tree(["source/", "source/b/", "source/b/b"])
import_dir(tree, "source", target_tree=file_ids_tree)
if tree.supports_setting_file_ids():
self.assertEqual(b"a-id", tree.path2id("b"))
self.assertEqual(b"b-id", tree.path2id("b/b"))
def test_nonascii_filename(self):
self.requireFeature(tests.UnicodeFilenameFeature)
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
self.build_tree(["source/", "source/\xa7"])
import_dir(tree, "source")
self.assertEqual({'', "\xa7"}, tree.all_versioned_paths())
if tree.supports_setting_file_ids():
self.assertEqual(
["", "\xa7"],
sorted([tree.id2path(i) for i in tree.all_file_ids()]))
def test_exclude(self):
tree = self.make_branch_and_tree(".")
tree.lock_write()
self.addCleanup(tree.unlock)
self.build_tree(["source/", "source/not-excluded", "source/test"])
import_dir(tree, "source", exclude=['test'])
self.assertEqual({'', 'not-excluded'}, tree.all_versioned_paths())
if tree.supports_setting_file_ids():
self.assertEqual(
["", "not-excluded"],
sorted([tree.id2path(i) for i in tree.all_file_ids()]))
|