18
18
from cStringIO import StringIO
21
from bzrlib import ignores
23
22
from bzrlib.branch import Branch
24
from bzrlib import bzrdir, conflicts, errors, workingtree
23
import bzrlib.bzrdir as bzrdir
25
24
from bzrlib.bzrdir import BzrDir
25
from bzrlib.conflicts import *
26
import bzrlib.errors as errors
26
27
from bzrlib.errors import NotBranchError, NotVersionedError
27
28
from bzrlib.lockdir import LockDir
28
29
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
29
30
from bzrlib.tests import TestCaseWithTransport, TestSkipped
30
31
from bzrlib.trace import mutter
31
32
from bzrlib.transport import get_transport
33
import bzrlib.workingtree as workingtree
32
34
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
204
206
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.pending_merges())
215
209
class TestFormat2WorkingTree(TestCaseWithTransport):
216
210
"""Tests that are specific to format 2 trees."""
225
219
self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
227
221
file('lala.BASE', 'wb').write('labase')
228
expected = conflicts.ContentsConflict('lala')
222
expected = ContentsConflict('lala')
229
223
self.assertEqual(list(tree.conflicts()), [expected])
230
224
file('lala', 'wb').write('la')
231
225
tree.add('lala', 'lala-id')
232
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
226
expected = ContentsConflict('lala', file_id='lala-id')
233
227
self.assertEqual(list(tree.conflicts()), [expected])
234
228
file('lala.THIS', 'wb').write('lathis')
235
229
file('lala.OTHER', 'wb').write('laother')
236
230
# When "text conflict"s happen, stem, THIS and OTHER are text
237
expected = conflicts.TextConflict('lala', file_id='lala-id')
231
expected = TextConflict('lala', file_id='lala-id')
238
232
self.assertEqual(list(tree.conflicts()), [expected])
239
233
os.unlink('lala.OTHER')
240
234
os.mkdir('lala.OTHER')
241
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
235
expected = ContentsConflict('lala', file_id='lala-id')
242
236
self.assertEqual(list(tree.conflicts()), [expected])
249
243
def test_gen_file_id(self):
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)
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-')
282
249
def test_next_id_suffix(self):
283
250
bzrlib.workingtree._gen_id_suffix = None
343
310
def test__get_ignore_rules_as_regex(self):
344
311
tree = self.make_branch_and_tree('.')
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
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])