18
18
from cStringIO import StringIO
21
from bzrlib import ignores
22
23
from bzrlib.branch import Branch
23
import bzrlib.bzrdir as bzrdir
24
from bzrlib import bzrdir, conflicts, errors, workingtree
24
25
from bzrlib.bzrdir import BzrDir
25
from bzrlib.conflicts import *
26
import bzrlib.errors as errors
27
26
from bzrlib.errors import NotBranchError, NotVersionedError
28
27
from bzrlib.lockdir import LockDir
29
28
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
30
29
from bzrlib.tests import TestCaseWithTransport, TestSkipped
31
30
from bzrlib.trace import mutter
32
31
from bzrlib.transport import get_transport
33
import bzrlib.workingtree as workingtree
34
32
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
92
90
def initialize(self, a_bzrdir, revision_id=None):
93
91
"""Sample branches cannot be created."""
94
92
t = a_bzrdir.get_workingtree_transport(self)
95
t.put('format', StringIO(self.get_format_string()))
93
t.put_bytes('format', self.get_format_string())
98
96
def is_supported(self):
206
204
self.assertEquals(our_lock.peek(), None)
206
def test_missing_pending_merges(self):
207
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
208
control.create_repository()
209
control.create_branch()
210
tree = workingtree.WorkingTreeFormat3().initialize(control)
211
tree._control_files._transport.delete("pending-merges")
212
self.assertEqual([], tree.get_parent_ids())
209
215
class TestFormat2WorkingTree(TestCaseWithTransport):
210
216
"""Tests that are specific to format 2 trees."""
219
225
self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
221
227
file('lala.BASE', 'wb').write('labase')
222
expected = ContentsConflict('lala')
228
expected = conflicts.ContentsConflict('lala')
223
229
self.assertEqual(list(tree.conflicts()), [expected])
224
230
file('lala', 'wb').write('la')
225
231
tree.add('lala', 'lala-id')
226
expected = ContentsConflict('lala', file_id='lala-id')
232
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
227
233
self.assertEqual(list(tree.conflicts()), [expected])
228
234
file('lala.THIS', 'wb').write('lathis')
229
235
file('lala.OTHER', 'wb').write('laother')
230
236
# When "text conflict"s happen, stem, THIS and OTHER are text
231
expected = TextConflict('lala', file_id='lala-id')
237
expected = conflicts.TextConflict('lala', file_id='lala-id')
232
238
self.assertEqual(list(tree.conflicts()), [expected])
233
239
os.unlink('lala.OTHER')
234
240
os.mkdir('lala.OTHER')
235
expected = ContentsConflict('lala', file_id='lala-id')
241
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
236
242
self.assertEqual(list(tree.conflicts()), [expected])
243
249
def test_gen_file_id(self):
244
self.assertStartsWith(bzrlib.workingtree.gen_file_id('bar'), 'bar-')
245
self.assertStartsWith(bzrlib.workingtree.gen_file_id('Mwoo oof\t m'), 'Mwoooofm-')
246
self.assertStartsWith(bzrlib.workingtree.gen_file_id('..gam.py'), 'gam.py-')
247
self.assertStartsWith(bzrlib.workingtree.gen_file_id('..Mwoo oof\t m'), 'Mwoooofm-')
250
gen_file_id = bzrlib.workingtree.gen_file_id
252
# We try to use the filename if possible
253
self.assertStartsWith(gen_file_id('bar'), 'bar-')
255
# but we squash capitalization, and remove non word characters
256
self.assertStartsWith(gen_file_id('Mwoo oof\t m'), 'mwoooofm-')
258
# We also remove leading '.' characters to prevent hidden file-ids
259
self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
260
self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
262
# we remove unicode characters, and still don't end up with a
264
self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
266
# Our current method of generating unique ids adds 33 characters
267
# plus an serial number (log10(N) characters)
268
# to the end of the filename. We now restrict the filename portion to
269
# be <= 20 characters, so the maximum length should now be approx < 60
271
# Test both case squashing and length restriction
272
fid = gen_file_id('A'*50 + '.txt')
273
self.assertStartsWith(fid, 'a'*20 + '-')
274
self.failUnless(len(fid) < 60)
276
# restricting length happens after the other actions, so
277
# we preserve as much as possible
278
fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
279
self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
280
self.failUnless(len(fid) < 60)
249
282
def test_next_id_suffix(self):
250
283
bzrlib.workingtree._gen_id_suffix = None
310
343
def test__get_ignore_rules_as_regex(self):
311
344
tree = self.make_branch_and_tree('.')
312
# test against the default rules.
313
reference_output = tree._combine_ignore_rules(bzrlib.DEFAULT_IGNORE)[0]
314
regex_rules = tree._get_ignore_rules_as_regex()[0]
315
self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
316
self.assertEqual(reference_output[1], regex_rules[1])
345
# Setup the default ignore list to be empty
346
ignores._set_user_ignores([])
348
# some plugins (shelf) modifies the DEFAULT_IGNORE list in memory
349
# which causes this test to fail so force the DEFAULT_IGNORE
351
orig_default = bzrlib.DEFAULT_IGNORE
352
# Also make sure the runtime ignore list is empty
353
orig_runtime = ignores._runtime_ignores
355
bzrlib.DEFAULT_IGNORE = []
356
ignores._runtime_ignores = set()
358
self.build_tree_contents([('.bzrignore', 'CVS\n.hg\n')])
359
reference_output = tree._combine_ignore_rules(
360
set(['CVS', '.hg']))[0]
361
regex_rules = tree._get_ignore_rules_as_regex()[0]
362
self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
363
self.assertEqual(reference_output[1], regex_rules[1])
365
bzrlib.DEFAULT_IGNORE = orig_default
366
ignores._runtime_ignores = orig_runtime