~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-07 04:44:56 UTC
  • mfrom: (3297.1.3 test-progress)
  • Revision ID: pqm@pqm.ubuntu.com-20080407044456-s1a9orh0kssphdh9
(mbp) more compact test progress counter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib import (
18
18
    branch as _mod_branch,
19
 
    bzrdir,
20
19
    errors,
21
20
    reconfigure,
22
21
    repository,
44
43
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
45
44
                          'tree')
46
45
 
47
 
    def test_tree_with_pending_merge_to_branch(self):
48
 
        tree = self.make_branch_and_tree('tree')
49
 
        other_tree = tree.bzrdir.sprout('other').open_workingtree()
50
 
        self.build_tree(['other/file'])
51
 
        other_tree.add('file')
52
 
        other_tree.commit('file added')
53
 
        tree.merge_from_branch(other_tree.branch)
54
 
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
55
 
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
56
 
        reconfiguration.apply(force=True)
57
 
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
58
 
                          'tree')
59
 
 
60
46
    def test_branch_to_branch(self):
61
47
        branch = self.make_branch('branch')
62
48
        self.assertRaises(errors.AlreadyBranch,
211
197
        self.assertRaises(errors.AlreadyCheckout,
212
198
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
213
199
 
214
 
    def make_unsynced_checkout(self):
 
200
    def test_checkout_to_lightweight(self):
215
201
        parent = self.make_branch('parent')
216
202
        checkout = parent.create_checkout('checkout')
217
203
        checkout.commit('test', rev_id='new-commit', local=True)
218
204
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
219
205
            checkout.bzrdir)
220
 
        return checkout, parent, reconfiguration
221
 
 
222
 
    def test_unsynced_checkout_to_lightweight(self):
223
 
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
224
 
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
225
 
 
226
 
    def test_synced_checkout_to_lightweight(self):
227
 
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
228
 
        parent.pull(checkout.branch)
229
206
        reconfiguration.apply()
230
207
        wt = checkout.bzrdir.open_workingtree()
231
208
        self.assertTrue(parent.repository.has_same_location(
238
215
        parent = self.make_branch('parent')
239
216
        child = parent.bzrdir.sprout('child').open_workingtree()
240
217
        child.commit('test', rev_id='new-commit')
241
 
        parent.pull(child.branch)
242
218
        child.bzrdir.destroy_workingtree()
243
219
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
244
220
            child.bzrdir)
310
286
        workingtree.WorkingTree.open('repo')
311
287
        self.assertRaises(errors.NoRepositoryPresent,
312
288
                          repository.Repository.open, 'repo')
313
 
 
314
 
    def test_standalone_to_use_shared(self):
315
 
        self.build_tree(['root/'])
316
 
        tree = self.make_branch_and_tree('root/tree')
317
 
        tree.commit('Hello', rev_id='hello-id')
318
 
        repo = self.make_repository('root', shared=True)
319
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
320
 
        reconfiguration.apply()
321
 
        tree = workingtree.WorkingTree.open('root/tree')
322
 
        self.assertTrue(repo.has_same_location(tree.branch.repository))
323
 
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
324
 
 
325
 
    def add_dead_head(self, tree):
326
 
        revno, revision_id = tree.branch.last_revision_info()
327
 
        tree.commit('Dead head', rev_id='dead-head-id')
328
 
        tree.branch.set_last_revision_info(revno, revision_id)
329
 
        tree.set_last_revision(revision_id)
330
 
 
331
 
    def test_standalone_to_use_shared_preserves_dead_heads(self):
332
 
        self.build_tree(['root/'])
333
 
        tree = self.make_branch_and_tree('root/tree')
334
 
        self.add_dead_head(tree)
335
 
        tree.commit('Hello', rev_id='hello-id')
336
 
        repo = self.make_repository('root', shared=True)
337
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
338
 
        reconfiguration.apply()
339
 
        tree = workingtree.WorkingTree.open('root/tree')
340
 
        message = repo.get_revision('dead-head-id').message
341
 
        self.assertEqual('Dead head', message)
342
 
 
343
 
    def make_repository_tree(self):
344
 
        self.build_tree(['root/'])
345
 
        repo = self.make_repository('root', shared=True)
346
 
        tree = self.make_branch_and_tree('root/tree')
347
 
        reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
348
 
        return workingtree.WorkingTree.open('root/tree')
349
 
 
350
 
    def test_use_shared_to_use_shared(self):
351
 
        tree = self.make_repository_tree()
352
 
        self.assertRaises(errors.AlreadyUsingShared,
353
 
                          reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
354
 
 
355
 
    def test_use_shared_to_standalone(self):
356
 
        tree = self.make_repository_tree()
357
 
        tree.commit('Hello', rev_id='hello-id')
358
 
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
359
 
        tree = workingtree.WorkingTree.open('root/tree')
360
 
        repo = tree.branch.repository
361
 
        self.assertEqual(repo.bzrdir.root_transport.base,
362
 
                         tree.bzrdir.root_transport.base)
363
 
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
364
 
 
365
 
    def test_use_shared_to_standalone_preserves_dead_heads(self):
366
 
        tree = self.make_repository_tree()
367
 
        self.add_dead_head(tree)
368
 
        tree.commit('Hello', rev_id='hello-id')
369
 
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
370
 
        tree = workingtree.WorkingTree.open('root/tree')
371
 
        repo = tree.branch.repository
372
 
        self.assertRaises(errors.NoSuchRevision, repo.get_revision,
373
 
                          'dead-head-id')
374
 
 
375
 
    def test_standalone_to_standalone(self):
376
 
        tree = self.make_branch_and_tree('tree')
377
 
        self.assertRaises(errors.AlreadyStandalone,
378
 
                          reconfigure.Reconfigure.to_standalone, tree.bzrdir)
379
 
 
380
 
    def make_unsynced_branch_reconfiguration(self):
381
 
        parent = self.make_branch_and_tree('parent')
382
 
        parent.commit('commit 1')
383
 
        child = parent.bzrdir.sprout('child').open_workingtree()
384
 
        child.commit('commit 2')
385
 
        return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
386
 
 
387
 
    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
388
 
        reconfiguration = self.make_unsynced_branch_reconfiguration()
389
 
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
390
 
 
391
 
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
392
 
        reconfiguration = self.make_unsynced_branch_reconfiguration()
393
 
        reconfiguration.apply(force=True)
394
 
 
395
 
    def make_repository_with_without_trees(self, with_trees):
396
 
        repo = self.make_repository('repo', shared=True)
397
 
        repo.set_make_working_trees(with_trees)
398
 
        return repo
399
 
 
400
 
    def test_make_with_trees(self):
401
 
        repo = self.make_repository_with_without_trees(False)
402
 
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
403
 
            repo.bzrdir, True)
404
 
        reconfiguration.apply()
405
 
        self.assertIs(True, repo.make_working_trees())
406
 
 
407
 
    def test_make_without_trees(self):
408
 
        repo = self.make_repository_with_without_trees(True)
409
 
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
410
 
            repo.bzrdir, False)
411
 
        reconfiguration.apply()
412
 
        self.assertIs(False, repo.make_working_trees())
413
 
 
414
 
    def test_make_with_trees_already_with_trees(self):
415
 
        repo = self.make_repository_with_without_trees(True)
416
 
        e = self.assertRaises(errors.AlreadyWithTrees,
417
 
           reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
418
 
        self.assertContainsRe(str(e),
419
 
            r"Shared repository '.*' already creates working trees.")
420
 
 
421
 
    def test_make_without_trees_already_no_trees(self):
422
 
        repo = self.make_repository_with_without_trees(False)
423
 
        e = self.assertRaises(errors.AlreadyWithNoTrees,
424
 
            reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
425
 
        self.assertContainsRe(str(e),
426
 
            r"Shared repository '.*' already doesn't create working trees.")
427
 
 
428
 
    def test_repository_tree_reconfiguration_not_supported(self):
429
 
        tree = self.make_branch_and_tree('tree')
430
 
        e = self.assertRaises(errors.ReconfigurationNotSupported,
431
 
            reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
432
 
        self.assertContainsRe(str(e),
433
 
            r"Requested reconfiguration of '.*' is not supported.")
434
 
 
435
 
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
436
 
        format = bzrdir.format_registry.make_bzrdir('1.9')
437
 
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
438
 
        tree = self.make_branch_and_tree('tree', format=format)
439
 
        tree.branch.set_reference_info('file_id', 'path', '../location')
440
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
441
 
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
442
 
        reconfiguration.apply()
443
 
        checkout_branch = checkout.bzrdir.open_branch()
444
 
        self.assertEqual(('path', '../location'),
445
 
                         checkout_branch.get_reference_info('file_id'))