~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib import (
23
23
    branch,
24
24
    errors,
 
25
    lock,
25
26
    merge as _mod_merge,
26
27
    switch,
27
28
    tests,
 
29
    workingtree,
28
30
    )
29
31
 
30
32
 
34
36
        super(TestSwitch, self).setUp()
35
37
        self.lightweight = True
36
38
 
 
39
    @staticmethod
 
40
    def _master_if_present(branch):
 
41
        master = branch.get_master_branch()
 
42
        if master:
 
43
            return master
 
44
        else:
 
45
            return branch
 
46
 
37
47
    def _setup_tree(self):
38
48
        tree = self.make_branch_and_tree('branch-1')
39
49
        self.build_tree(['branch-1/file-1'])
41
51
        tree.commit('rev1')
42
52
        return tree
43
53
 
 
54
    def _setup_uncommitted(self, same_revision=False):
 
55
        tree = self._setup_tree()
 
56
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
 
57
        self.build_tree(['branch-1/file-2'])
 
58
        if not same_revision:
 
59
            tree.add('file-2')
 
60
            tree.remove('file-1')
 
61
            tree.commit('rev2')
 
62
        checkout = tree.branch.create_checkout('checkout',
 
63
            lightweight=self.lightweight)
 
64
        self.build_tree(['checkout/file-3'])
 
65
        checkout.add('file-3')
 
66
        return checkout, to_branch
 
67
 
 
68
    def test_switch_store_uncommitted(self):
 
69
        """Test switch updates tree and stores uncommitted changes."""
 
70
        checkout, to_branch = self._setup_uncommitted()
 
71
        self.assertPathDoesNotExist('checkout/file-1')
 
72
        self.assertPathExists('checkout/file-2')
 
73
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
 
74
        self.assertPathExists('checkout/file-1')
 
75
        self.assertPathDoesNotExist('checkout/file-2')
 
76
        self.assertPathDoesNotExist('checkout/file-3')
 
77
 
 
78
    def test_switch_restore_uncommitted(self):
 
79
        """Test switch updates tree and restores uncommitted changes."""
 
80
        checkout, to_branch = self._setup_uncommitted()
 
81
        old_branch = self._master_if_present(checkout.branch)
 
82
        self.assertPathDoesNotExist('checkout/file-1')
 
83
        self.assertPathExists('checkout/file-2')
 
84
        self.assertPathExists('checkout/file-3')
 
85
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
 
86
        checkout = workingtree.WorkingTree.open('checkout')
 
87
        switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
 
88
        self.assertPathDoesNotExist('checkout/file-1')
 
89
        self.assertPathExists('checkout/file-2')
 
90
        self.assertPathExists('checkout/file-3')
 
91
 
 
92
    def test_switch_restore_uncommitted_same_revision(self):
 
93
        """Test switch updates tree and restores uncommitted changes."""
 
94
        checkout, to_branch = self._setup_uncommitted(same_revision=True)
 
95
        old_branch = self._master_if_present(checkout.branch)
 
96
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
 
97
        checkout = workingtree.WorkingTree.open('checkout')
 
98
        switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
 
99
        self.assertPathExists('checkout/file-3')
 
100
 
44
101
    def test_switch_updates(self):
45
102
        """Test switch updates tree and keeps uncommitted changes."""
46
 
        tree = self._setup_tree()
47
 
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
48
 
        self.build_tree(['branch-1/file-2'])
49
 
        tree.add('file-2')
50
 
        tree.remove('file-1')
51
 
        tree.commit('rev2')
52
 
        checkout = tree.branch.create_checkout('checkout',
53
 
            lightweight=self.lightweight)
54
 
        self.build_tree(['checkout/file-3'])
55
 
        checkout.add('file-3')
 
103
        checkout, to_branch = self._setup_uncommitted()
56
104
        self.assertPathDoesNotExist('checkout/file-1')
57
105
        self.assertPathExists('checkout/file-2')
58
106
        switch.switch(checkout.bzrdir, to_branch)