2999.1.4
by Ian Clatworthy
more review tweaks including commit of blackbox tests |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2999.1.4
by Ian Clatworthy
more review tweaks including commit of blackbox tests |
17 |
|
18 |
||
19 |
"""Tests for the switch command of bzr."""
|
|
20 |
||
21 |
import os |
|
22 |
||
3565.6.7
by Marius Kruger
* checkouts now use master nick when no explicit nick is set. |
23 |
from bzrlib.workingtree import WorkingTree |
2999.1.4
by Ian Clatworthy
more review tweaks including commit of blackbox tests |
24 |
from bzrlib.tests.blackbox import ExternalBase |
25 |
||
26 |
||
27 |
class TestSwitch(ExternalBase): |
|
28 |
||
29 |
def test_switch_up_to_date_light_checkout(self): |
|
30 |
self.make_branch_and_tree('branch') |
|
31 |
self.run_bzr('branch branch branch2') |
|
32 |
self.run_bzr('checkout --lightweight branch checkout') |
|
33 |
os.chdir('checkout') |
|
34 |
out, err = self.run_bzr('switch ../branch2') |
|
35 |
self.assertContainsRe(err, 'Tree is up to date at revision 0.\n') |
|
36 |
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n') |
|
37 |
self.assertEqual('', out) |
|
38 |
||
39 |
def test_switch_out_of_date_light_checkout(self): |
|
40 |
self.make_branch_and_tree('branch') |
|
41 |
self.run_bzr('branch branch branch2') |
|
42 |
self.build_tree(['branch2/file']) |
|
43 |
self.run_bzr('add branch2/file') |
|
44 |
self.run_bzr('commit -m add-file branch2') |
|
45 |
self.run_bzr('checkout --lightweight branch checkout') |
|
46 |
os.chdir('checkout') |
|
47 |
out, err = self.run_bzr('switch ../branch2') |
|
48 |
#self.assertContainsRe(err, '\+N file')
|
|
49 |
self.assertContainsRe(err, 'Updated to revision 1.\n') |
|
50 |
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n') |
|
51 |
self.assertEqual('', out) |
|
3246.5.1
by Robert Collins
* ``bzr switch`` will attempt to find branches to switch to relative to the |
52 |
|
3565.6.7
by Marius Kruger
* checkouts now use master nick when no explicit nick is set. |
53 |
def _test_switch_nick(self, lightweight): |
54 |
"""Check that the nick gets switched too."""
|
|
55 |
tree1 = self.make_branch_and_tree('branch1') |
|
56 |
tree2 = self.make_branch_and_tree('branch2') |
|
57 |
tree2.pull(tree1.branch) |
|
58 |
checkout = tree1.branch.create_checkout('checkout', |
|
59 |
lightweight=lightweight) |
|
60 |
self.assertEqual(checkout.branch.nick, tree1.branch.nick) |
|
61 |
self.assertEqual(checkout.branch.get_config().has_explicit_nickname(), |
|
62 |
False) |
|
63 |
self.run_bzr('switch branch2', working_dir='checkout') |
|
64 |
||
65 |
# we need to get the tree again, otherwise we don't get the new branch
|
|
66 |
checkout = WorkingTree.open('checkout') |
|
67 |
self.assertEqual(checkout.branch.nick, tree2.branch.nick) |
|
68 |
self.assertEqual(checkout.branch.get_config().has_explicit_nickname(), |
|
69 |
False) |
|
70 |
||
3565.6.1
by Marius Kruger
Let 'bzr switch' update the nick too. |
71 |
def test_switch_nick(self): |
3565.6.7
by Marius Kruger
* checkouts now use master nick when no explicit nick is set. |
72 |
self._test_switch_nick(lightweight=False) |
73 |
||
74 |
def test_switch_nick_lightweight(self): |
|
75 |
self._test_switch_nick(lightweight=True) |
|
76 |
||
77 |
def _test_switch_explicit_nick(self, lightweight): |
|
3565.6.1
by Marius Kruger
Let 'bzr switch' update the nick too. |
78 |
"""Check that the nick gets switched too."""
|
79 |
tree1 = self.make_branch_and_tree('branch1') |
|
80 |
tree2 = self.make_branch_and_tree('branch2') |
|
81 |
tree2.pull(tree1.branch) |
|
3565.6.7
by Marius Kruger
* checkouts now use master nick when no explicit nick is set. |
82 |
checkout = tree1.branch.create_checkout('checkout', |
83 |
lightweight=lightweight) |
|
84 |
self.assertEqual(checkout.branch.nick, tree1.branch.nick) |
|
85 |
checkout.branch.nick = "explicit_nick" |
|
86 |
self.assertEqual(checkout.branch.nick, "explicit_nick") |
|
87 |
self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(), |
|
88 |
"explicit_nick") |
|
89 |
self.run_bzr('switch branch2', working_dir='checkout') |
|
90 |
||
91 |
# we need to get the tree again, otherwise we don't get the new branch
|
|
92 |
checkout = WorkingTree.open('checkout') |
|
93 |
self.assertEqual(checkout.branch.nick, tree2.branch.nick) |
|
94 |
self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(), |
|
95 |
tree2.branch.nick) |
|
96 |
||
97 |
def test_switch_explicit_nick(self): |
|
98 |
self._test_switch_explicit_nick(lightweight=False) |
|
99 |
||
100 |
def test_switch_explicit_nick_lightweight(self): |
|
101 |
self._test_switch_explicit_nick(lightweight=True) |
|
3565.6.1
by Marius Kruger
Let 'bzr switch' update the nick too. |
102 |
|
3246.5.1
by Robert Collins
* ``bzr switch`` will attempt to find branches to switch to relative to the |
103 |
def test_switch_finds_relative_branch(self): |
3565.6.1
by Marius Kruger
Let 'bzr switch' update the nick too. |
104 |
"""Switch will find 'foo' relative to the branch the checkout is of."""
|
3246.5.1
by Robert Collins
* ``bzr switch`` will attempt to find branches to switch to relative to the |
105 |
self.build_tree(['repo/']) |
106 |
tree1 = self.make_branch_and_tree('repo/brancha') |
|
107 |
tree1.commit('foo') |
|
108 |
tree2 = self.make_branch_and_tree('repo/branchb') |
|
109 |
tree2.pull(tree1.branch) |
|
110 |
branchb_id = tree2.commit('bar') |
|
111 |
checkout = tree1.branch.create_checkout('checkout', lightweight=True) |
|
112 |
self.run_bzr(['switch', 'branchb'], working_dir='checkout') |
|
113 |
self.assertEqual(branchb_id, checkout.last_revision()) |
|
114 |
checkout = checkout.bzrdir.open_workingtree() |
|
115 |
self.assertEqual(tree2.branch.base, checkout.branch.base) |
|
3602.3.1
by Adrian Wilkins
Test that `bzr switch` finds the sibling of the bound branch of heavy checkout. |
116 |
|
117 |
def test_switch_finds_relative_bound_branch(self): |
|
3602.3.4
by Adrian Wilkins
Improved comments and documentation |
118 |
"""Using switch on a heavy checkout should find master sibling
|
119 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
120 |
The behaviour of lighweight and heavy checkouts should be
|
3602.3.4
by Adrian Wilkins
Improved comments and documentation |
121 |
consistentwhen using the convenient "switch to sibling" feature
|
122 |
Both should switch to a sibling of the branch
|
|
123 |
they are bound to, and not a sibling of themself"""
|
|
124 |
||
3602.3.1
by Adrian Wilkins
Test that `bzr switch` finds the sibling of the bound branch of heavy checkout. |
125 |
self.build_tree(['repo/', |
126 |
'heavyco/']) |
|
127 |
tree1 = self.make_branch_and_tree('repo/brancha') |
|
128 |
tree1.commit('foo') |
|
129 |
tree2 = self.make_branch_and_tree('repo/branchb') |
|
130 |
tree2.pull(tree1.branch) |
|
131 |
branchb_id = tree2.commit('bar') |
|
132 |
checkout = tree1.branch.create_checkout('heavyco/a', lightweight=False) |
|
133 |
self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a') |
|
134 |
self.assertEqual(branchb_id, checkout.last_revision()) |
|
135 |
self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location()) |