4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
|
3586.1.22
by Ian Clatworthy
add initial filtered-view-ops tests |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3586.1.22
by Ian Clatworthy
add initial filtered-view-ops tests |
16 |
|
17 |
"""Tests that an enabled view is reported and impacts expected commands."""
|
|
18 |
||
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
19 |
import os |
20 |
||
4879.1.3
by Vincent Ladeuil
Cleanup tests and tweak the text displayed. |
21 |
from bzrlib import ( |
22 |
bzrdir, |
|
23 |
osutils, |
|
24 |
tests, |
|
25 |
)
|
|
26 |
||
27 |
||
28 |
class TestViewFileOperations(tests.TestCaseWithTransport): |
|
3586.1.22
by Ian Clatworthy
add initial filtered-view-ops tests |
29 |
|
30 |
def make_abc_tree_with_ab_view(self): |
|
31 |
# we need to use a specific format because the default format
|
|
32 |
# doesn't support views yet
|
|
4241.6.8
by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil) |
33 |
format = bzrdir.format_registry.make_bzrdir('development6-rich-root') |
4879.1.3
by Vincent Ladeuil
Cleanup tests and tweak the text displayed. |
34 |
wt = self.make_branch_and_tree( '.', format=format) |
3586.1.22
by Ian Clatworthy
add initial filtered-view-ops tests |
35 |
self.build_tree(['a', 'b', 'c']) |
3586.1.25
by Ian Clatworthy
tweak tests |
36 |
wt.views.set_view('my', ['a', 'b']) |
3586.1.22
by Ian Clatworthy
add initial filtered-view-ops tests |
37 |
return wt |
38 |
||
39 |
def test_view_on_status(self): |
|
40 |
wt = self.make_abc_tree_with_ab_view() |
|
41 |
out, err = self.run_bzr('status') |
|
4210.1.1
by Ian Clatworthy
reword 'ignoring files outside view' message |
42 |
self.assertEquals('Ignoring files outside view. View is a, b\n', err) |
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
43 |
self.assertEquals('unknown:\n a\n b\n', out) |
44 |
||
3586.1.27
by Ian Clatworthy
more filtered operation tests |
45 |
def test_view_on_status_selected(self): |
46 |
wt = self.make_abc_tree_with_ab_view() |
|
47 |
out, err = self.run_bzr('status a') |
|
48 |
self.assertEquals('', err) |
|
49 |
self.assertEquals('unknown:\n a\n', out) |
|
50 |
out, err = self.run_bzr('status c', retcode=3) |
|
51 |
self.assertEquals('bzr: ERROR: Specified file "c" is outside the ' |
|
52 |
'current view: a, b\n', err) |
|
53 |
self.assertEquals('', out) |
|
54 |
||
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
55 |
def test_view_on_add(self): |
56 |
wt = self.make_abc_tree_with_ab_view() |
|
57 |
out, err = self.run_bzr('add') |
|
4210.1.1
by Ian Clatworthy
reword 'ignoring files outside view' message |
58 |
self.assertEquals('Ignoring files outside view. View is a, b\n', err) |
4075.1.1
by Robert Collins
add should not print 'add completed' unnecessarily. |
59 |
self.assertEquals('adding a\nadding b\n', out) |
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
60 |
|
3586.1.27
by Ian Clatworthy
more filtered operation tests |
61 |
def test_view_on_add_selected(self): |
62 |
wt = self.make_abc_tree_with_ab_view() |
|
63 |
out, err = self.run_bzr('add a') |
|
64 |
self.assertEquals('', err) |
|
4075.1.1
by Robert Collins
add should not print 'add completed' unnecessarily. |
65 |
self.assertEquals('adding a\n', out) |
3586.1.27
by Ian Clatworthy
more filtered operation tests |
66 |
out, err = self.run_bzr('add c', retcode=3) |
67 |
self.assertEquals('bzr: ERROR: Specified file "c" is outside the ' |
|
68 |
'current view: a, b\n', err) |
|
69 |
self.assertEquals('', out) |
|
70 |
||
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
71 |
def test_view_on_diff(self): |
72 |
wt = self.make_abc_tree_with_ab_view() |
|
73 |
self.run_bzr('add') |
|
74 |
out, err = self.run_bzr('diff', retcode=1) |
|
4210.1.1
by Ian Clatworthy
reword 'ignoring files outside view' message |
75 |
self.assertEquals('*** Ignoring files outside view. View is a, b\n', err) |
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
76 |
|
3586.1.27
by Ian Clatworthy
more filtered operation tests |
77 |
def test_view_on_diff_selected(self): |
78 |
wt = self.make_abc_tree_with_ab_view() |
|
79 |
self.run_bzr('add') |
|
80 |
out, err = self.run_bzr('diff a', retcode=1) |
|
81 |
self.assertEquals('', err) |
|
82 |
self.assertStartsWith(out, "=== added file 'a'\n") |
|
83 |
out, err = self.run_bzr('diff c', retcode=3) |
|
84 |
self.assertEquals('bzr: ERROR: Specified file "c" is outside the ' |
|
85 |
'current view: a, b\n', err) |
|
86 |
self.assertEquals('', out) |
|
87 |
||
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
88 |
def test_view_on_commit(self): |
89 |
wt = self.make_abc_tree_with_ab_view() |
|
90 |
self.run_bzr('add') |
|
91 |
out, err = self.run_bzr('commit -m "testing commit"') |
|
92 |
err_lines = err.splitlines() |
|
4210.1.1
by Ian Clatworthy
reword 'ignoring files outside view' message |
93 |
self.assertEquals('Ignoring files outside view. View is a, b', err_lines[0]) |
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
94 |
self.assertStartsWith(err_lines[1], 'Committing to:') |
95 |
self.assertEquals('added a', err_lines[2]) |
|
96 |
self.assertEquals('added b', err_lines[3]) |
|
97 |
self.assertEquals('Committed revision 1.', err_lines[4]) |
|
98 |
self.assertEquals('', out) |
|
99 |
||
3586.1.27
by Ian Clatworthy
more filtered operation tests |
100 |
def test_view_on_commit_selected(self): |
101 |
wt = self.make_abc_tree_with_ab_view() |
|
102 |
self.run_bzr('add') |
|
103 |
out, err = self.run_bzr('commit -m "file in view" a') |
|
104 |
err_lines = err.splitlines() |
|
105 |
self.assertStartsWith(err_lines[0], 'Committing to:') |
|
106 |
self.assertEquals('added a', err_lines[1]) |
|
107 |
self.assertEquals('Committed revision 1.', err_lines[2]) |
|
108 |
self.assertEquals('', out) |
|
109 |
out, err = self.run_bzr('commit -m "file out of view" c', retcode=3) |
|
110 |
self.assertEquals('bzr: ERROR: Specified file "c" is outside the ' |
|
111 |
'current view: a, b\n', err) |
|
112 |
self.assertEquals('', out) |
|
113 |
||
114 |
def test_view_on_remove_selected(self): |
|
3586.1.26
by Ian Clatworthy
add more filtered view operation tests |
115 |
wt = self.make_abc_tree_with_ab_view() |
116 |
self.run_bzr('add') |
|
117 |
out, err = self.run_bzr('remove --keep a') |
|
118 |
self.assertEquals('removed a\n', err) |
|
119 |
self.assertEquals('', out) |
|
120 |
out, err = self.run_bzr('remove --keep c', retcode=3) |
|
121 |
self.assertEquals('bzr: ERROR: Specified file "c" is outside the ' |
|
122 |
'current view: a, b\n', err) |
|
123 |
self.assertEquals('', out) |
|
3586.1.27
by Ian Clatworthy
more filtered operation tests |
124 |
|
125 |
def test_view_on_revert(self): |
|
126 |
wt = self.make_abc_tree_with_ab_view() |
|
127 |
self.run_bzr('add') |
|
128 |
out, err = self.run_bzr('revert') |
|
129 |
err_lines = err.splitlines() |
|
4210.1.1
by Ian Clatworthy
reword 'ignoring files outside view' message |
130 |
self.assertEquals('Ignoring files outside view. View is a, b', err_lines[0]) |
3586.1.27
by Ian Clatworthy
more filtered operation tests |
131 |
self.assertEquals('- a', err_lines[1]) |
132 |
self.assertEquals('- b', err_lines[2]) |
|
133 |
self.assertEquals('', out) |
|
134 |
||
135 |
def test_view_on_revert_selected(self): |
|
136 |
wt = self.make_abc_tree_with_ab_view() |
|
137 |
self.run_bzr('add') |
|
138 |
out, err = self.run_bzr('revert a') |
|
139 |
self.assertEquals('- a\n', err) |
|
140 |
self.assertEquals('', out) |
|
141 |
out, err = self.run_bzr('revert c', retcode=3) |
|
142 |
self.assertEquals('bzr: ERROR: Specified file "c" is outside the ' |
|
143 |
'current view: a, b\n', err) |
|
144 |
self.assertEquals('', out) |
|
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
145 |
|
4032.4.4
by Eduardo Padoan
Added tests for ls when using a view. |
146 |
def test_view_on_ls(self): |
147 |
wt = self.make_abc_tree_with_ab_view() |
|
148 |
self.run_bzr('add') |
|
149 |
out, err = self.run_bzr('ls') |
|
150 |
out_lines = out.splitlines() |
|
4210.1.1
by Ian Clatworthy
reword 'ignoring files outside view' message |
151 |
self.assertEquals('Ignoring files outside view. View is a, b\n', err) |
4032.4.4
by Eduardo Padoan
Added tests for ls when using a view. |
152 |
self.assertEquals('a', out_lines[0]) |
153 |
self.assertEquals('b', out_lines[1]) |
|
154 |
||
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
155 |
|
4879.1.3
by Vincent Ladeuil
Cleanup tests and tweak the text displayed. |
156 |
class TestViewTreeOperations(tests.TestCaseWithTransport): |
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
157 |
|
158 |
def make_abc_tree_and_clone_with_ab_view(self): |
|
159 |
# we need to use a specific format because the default format
|
|
160 |
# doesn't support views yet
|
|
4241.6.8
by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil) |
161 |
format = bzrdir.format_registry.make_bzrdir('development6-rich-root') |
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
162 |
# Build the first tree
|
4879.1.3
by Vincent Ladeuil
Cleanup tests and tweak the text displayed. |
163 |
wt1 = self.make_branch_and_tree('tree_1', format=format) |
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
164 |
self.build_tree(['tree_1/a', 'tree_1/b', 'tree_1/c']) |
165 |
wt1.add(['a', 'b', 'c']) |
|
166 |
wt1.commit("adding a b c") |
|
167 |
# Build the second tree and give it a view
|
|
168 |
wt2 = wt1.bzrdir.sprout('tree_2').open_workingtree() |
|
169 |
wt2.views.set_view('my', ['a', 'b']) |
|
170 |
# Commit a change to the first tree
|
|
171 |
self.build_tree_contents([ |
|
172 |
('tree_1/a', 'changed a\n'), |
|
173 |
('tree_1/c', 'changed c\n'), |
|
174 |
])
|
|
175 |
wt1.commit("changing a c") |
|
176 |
return wt1, wt2 |
|
177 |
||
178 |
def test_view_on_pull(self): |
|
179 |
tree_1, tree_2 = self.make_abc_tree_and_clone_with_ab_view() |
|
180 |
out, err = self.run_bzr('pull -d tree_2 tree_1') |
|
181 |
self.assertEqualDiff( |
|
182 |
"Operating on whole tree but only reporting on 'my' view.\n" |
|
183 |
" M a\n" |
|
184 |
"All changes applied successfully.\n", err) |
|
185 |
self.assertEqualDiff("Now on revision 2.\n", out) |
|
186 |
||
187 |
def test_view_on_update(self): |
|
188 |
tree_1, tree_2 = self.make_abc_tree_and_clone_with_ab_view() |
|
4879.1.3
by Vincent Ladeuil
Cleanup tests and tweak the text displayed. |
189 |
self.run_bzr("bind ../tree_1", working_dir='tree_2') |
190 |
out, err = self.run_bzr('update', working_dir='tree_2') |
|
191 |
self.assertEqualDiff( |
|
192 |
"""Operating on whole tree but only reporting on 'my' view.
|
|
193 |
M a
|
|
194 |
All changes applied successfully.
|
|
195 |
Updated to revision 2 of branch %s
|
|
196 |
""" % osutils.pathjoin(self.test_dir, 'tree_1'), |
|
197 |
err) |
|
198 |
self.assertEqual("", out) |
|
3586.1.31
by Ian Clatworthy
view filtering for pull, update & merge |
199 |
|
200 |
def test_view_on_merge(self): |
|
201 |
tree_1, tree_2 = self.make_abc_tree_and_clone_with_ab_view() |
|
202 |
out, err = self.run_bzr('merge -d tree_2 tree_1') |
|
203 |
self.assertEqualDiff( |
|
204 |
"Operating on whole tree but only reporting on 'my' view.\n" |
|
205 |
" M a\n" |
|
206 |
"All changes applied successfully.\n", err) |
|
4879.1.3
by Vincent Ladeuil
Cleanup tests and tweak the text displayed. |
207 |
self.assertEqual("", out) |