2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
1 |
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
|
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
#
|
|
17 |
||
18 |
"""Tests of the 'bzr add' command."""
|
|
19 |
||
20 |
import os |
|
21 |
||
22 |
from bzrlib.tests.blackbox import ExternalBase |
|
23 |
||
24 |
||
25 |
class TestAdd(ExternalBase): |
|
26 |
||
27 |
def test_add_reports(self): |
|
28 |
"""add command prints the names of added files."""
|
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
29 |
self.run_bzr('init') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
30 |
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS']) |
1765.1.1
by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add. |
31 |
self.build_tree_contents([('.bzrignore', 'CVS\n')]) |
2581.1.2
by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls |
32 |
out = self.run_bzr('add')[0] |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
33 |
# the ordering is not defined at the moment
|
34 |
results = sorted(out.rstrip('\n').split('\n')) |
|
35 |
self.assertEquals(['If you wish to add some of these files, please'\ |
|
36 |
' add them by name.', |
|
1765.1.1
by Robert Collins
Remove the default ignores list from bzr, lowering the minimum overhead in bzr add. |
37 |
'added .bzrignore', |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
38 |
'added dir', |
39 |
'added dir/sub.txt', |
|
40 |
'added top.txt', |
|
1987.1.1
by John Arbash Meinel
Update the test suite to put HOME in a different directory |
41 |
'ignored 1 file(s).'], |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
42 |
results) |
2581.1.2
by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls |
43 |
out = self.run_bzr('add -v')[0] |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
44 |
results = sorted(out.rstrip('\n').split('\n')) |
45 |
self.assertEquals(['If you wish to add some of these files, please'\ |
|
46 |
' add them by name.', |
|
47 |
'ignored CVS matching "CVS"'], |
|
48 |
results) |
|
49 |
||
50 |
def test_add_quiet_is(self): |
|
51 |
"""add -q does not print the names of added files."""
|
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
52 |
self.run_bzr('init') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
53 |
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt']) |
2581.1.2
by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls |
54 |
out = self.run_bzr('add -q')[0] |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
55 |
# the ordering is not defined at the moment
|
56 |
results = sorted(out.rstrip('\n').split('\n')) |
|
57 |
self.assertEquals([''], results) |
|
58 |
||
59 |
def test_add_in_unversioned(self): |
|
60 |
"""Try to add a file in an unversioned directory.
|
|
61 |
||
62 |
"bzr add" should add the parent(s) as necessary.
|
|
63 |
"""
|
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
64 |
self.run_bzr('init') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
65 |
self.build_tree(['inertiatic/', 'inertiatic/esp']) |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
66 |
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
67 |
self.run_bzr('add inertiatic/esp') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
68 |
self.assertEquals(self.run_bzr('unknowns')[0], '') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
69 |
|
70 |
# Multiple unversioned parents
|
|
71 |
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt']) |
|
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
72 |
self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
73 |
self.run_bzr('add veil/cerpin/taxt') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
74 |
self.assertEquals(self.run_bzr('unknowns')[0], '') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
75 |
|
76 |
# Check whacky paths work
|
|
77 |
self.build_tree(['cicatriz/', 'cicatriz/esp']) |
|
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
78 |
self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
79 |
self.run_bzr('add inertiatic/../cicatriz/esp') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
80 |
self.assertEquals(self.run_bzr('unknowns')[0], '') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
81 |
|
82 |
def test_add_in_versioned(self): |
|
83 |
"""Try to add a file in a versioned directory.
|
|
84 |
||
85 |
"bzr add" should do this happily.
|
|
86 |
"""
|
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
87 |
self.run_bzr('init') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
88 |
self.build_tree(['inertiatic/', 'inertiatic/esp']) |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
89 |
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
90 |
self.run_bzr('add --no-recurse inertiatic') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
91 |
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
92 |
self.run_bzr('add inertiatic/esp') |
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
93 |
self.assertEquals(self.run_bzr('unknowns')[0], '') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
94 |
|
95 |
def test_subdir_add(self): |
|
96 |
"""Add in subdirectory should add only things from there down"""
|
|
97 |
from bzrlib.workingtree import WorkingTree |
|
1836.1.16
by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail. |
98 |
|
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
99 |
eq = self.assertEqual |
1836.1.16
by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail. |
100 |
ass = self.assertTrue |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
101 |
chdir = os.chdir |
102 |
||
103 |
t = self.make_branch_and_tree('.') |
|
104 |
b = t.branch |
|
105 |
self.build_tree(['src/', 'README']) |
|
106 |
||
107 |
eq(sorted(t.unknowns()), |
|
108 |
['README', 'src']) |
|
109 |
||
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
110 |
self.run_bzr('add src') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
111 |
|
112 |
self.build_tree(['src/foo.c']) |
|
113 |
||
2255.2.171
by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory |
114 |
# add with no arguments in a subdirectory gets only files below that
|
115 |
# subdirectory
|
|
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
116 |
chdir('src') |
117 |
self.run_bzr('add') |
|
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
118 |
self.assertEquals(self.run_bzr('unknowns')[0], 'README\n') |
2255.2.176
by Martin Pool
Merge dirstate and some small cleanups |
119 |
# reopen to see the new changes
|
120 |
t = t.bzrdir.open_workingtree() |
|
2255.2.171
by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory |
121 |
versioned = [path for path, entry in t.iter_entries_by_dir()] |
122 |
self.assertEquals(versioned, |
|
123 |
['', 'src', 'src/foo.c']) |
|
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
124 |
|
2255.2.171
by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory |
125 |
# add from the parent directory should pick up all file names
|
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
126 |
chdir('..') |
127 |
self.run_bzr('add') |
|
2552.2.2
by Vincent Ladeuil
Enforce run_bzr(string) where possible. |
128 |
self.assertEquals(self.run_bzr('unknowns')[0], '') |
1711.1.3
by Robert Collins
Add new test_add file - should have been in last commit. |
129 |
self.run_bzr('check') |
1757.2.1
by Robert Collins
Add an explicit test that adding a missing file barfs. |
130 |
|
131 |
def test_add_missing(self): |
|
132 |
"""bzr add foo where foo is missing should error."""
|
|
133 |
self.make_branch_and_tree('.') |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
134 |
self.run_bzr('add missing-file', retcode=3) |
1911.3.2
by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree |
135 |
|
136 |
def test_add_from(self): |
|
137 |
base_tree = self.make_branch_and_tree('base') |
|
138 |
self.build_tree(['base/a', 'base/b/', 'base/b/c']) |
|
139 |
base_tree.add(['a', 'b', 'b/c']) |
|
140 |
base_tree.commit('foo') |
|
141 |
||
142 |
new_tree = self.make_branch_and_tree('new') |
|
143 |
self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd']) |
|
144 |
||
145 |
os.chdir('new') |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
146 |
out, err = self.run_bzr('add --file-ids-from ../base') |
1911.3.2
by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree |
147 |
self.assertEqual('', err) |
148 |
self.assertEqualDiff('added a w/ file id from a\n' |
|
149 |
'added b w/ file id from b\n' |
|
150 |
'added b/c w/ file id from b/c\n', |
|
151 |
out) |
|
2255.2.171
by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory |
152 |
new_tree = new_tree.bzrdir.open_workingtree() |
1911.3.2
by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree |
153 |
self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a')) |
154 |
self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b')) |
|
155 |
self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c')) |
|
156 |
||
157 |
def test_add_from_subdir(self): |
|
158 |
base_tree = self.make_branch_and_tree('base') |
|
159 |
self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d']) |
|
160 |
base_tree.add(['a', 'b', 'b/c', 'b/d']) |
|
161 |
base_tree.commit('foo') |
|
162 |
||
163 |
new_tree = self.make_branch_and_tree('new') |
|
164 |
self.build_tree(['new/c', 'new/d']) |
|
165 |
||
166 |
os.chdir('new') |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
167 |
out, err = self.run_bzr('add --file-ids-from ../base/b') |
1911.3.2
by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree |
168 |
self.assertEqual('', err) |
169 |
self.assertEqualDiff('added c w/ file id from b/c\n' |
|
170 |
'added d w/ file id from b/d\n', |
|
171 |
out) |
|
172 |
||
2255.2.171
by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory |
173 |
new_tree = new_tree.bzrdir.open_workingtree() |
1911.3.2
by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree |
174 |
self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c')) |
175 |
self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d')) |
|
1928.1.1
by Alexander Belchenko
blackbox test for 'bzr add --dry-run' |
176 |
|
177 |
def test_add_dry_run(self): |
|
2568.2.4
by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now |
178 |
"""Test a dry run add, make sure nothing is added."""
|
179 |
wt = self.make_branch_and_tree('.') |
|
180 |
self.build_tree(['inertiatic/', 'inertiatic/esp']) |
|
181 |
self.assertEqual(list(wt.unknowns()), ['inertiatic']) |
|
182 |
self.run_bzr('add --dry-run') |
|
183 |
self.assertEqual(list(wt.unknowns()), ['inertiatic']) |
|
2279.5.1
by Matthias Rahlf
FastPath objects can now be printed nicely |
184 |
|
185 |
def test_add_control_dir(self): |
|
186 |
"""The control dir and its content should be refused."""
|
|
2279.6.1
by Alexander Belchenko
Instead of __str__ method for FastPath object we use .raw_path attribute (note from Aaron). |
187 |
self.make_branch_and_tree('.') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
188 |
err = self.run_bzr('add .bzr', retcode=3)[1] |
2279.5.1
by Matthias Rahlf
FastPath objects can now be printed nicely |
189 |
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file') |
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
190 |
err = self.run_bzr('add .bzr/README', retcode=3)[1] |
2279.5.1
by Matthias Rahlf
FastPath objects can now be printed nicely |
191 |
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file') |
192 |
self.build_tree(['.bzr/crescent']) |
|
2530.3.3
by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't |
193 |
err = self.run_bzr('add .bzr/crescent', retcode=3)[1] |
2279.5.1
by Matthias Rahlf
FastPath objects can now be printed nicely |
194 |
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file') |