22
22
from bzrlib.tests.blackbox import ExternalBase
23
from bzrlib.tests.test_win32utils import NeedsGlobExpansionFeature
26
25
class TestAdd(ExternalBase):
28
27
def test_add_reports(self):
29
28
"""add command prints the names of added files."""
30
tree = self.make_branch_and_tree('.')
31
30
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
32
31
self.build_tree_contents([('.bzrignore', 'CVS\n')])
33
out = self.run_bzr('add')[0]
32
out = self.run_bzr_captured(['add'], retcode=0)[0]
34
33
# the ordering is not defined at the moment
35
34
results = sorted(out.rstrip('\n').split('\n'))
36
35
self.assertEquals(['If you wish to add some of these files, please'\
51
50
def test_add_quiet_is(self):
52
51
"""add -q does not print the names of added files."""
53
tree = self.make_branch_and_tree('.')
54
53
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
55
out = self.run_bzr('add -q')[0]
54
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
56
55
# the ordering is not defined at the moment
57
56
results = sorted(out.rstrip('\n').split('\n'))
58
57
self.assertEquals([''], results)
63
62
"bzr add" should add the parent(s) as necessary.
65
tree = self.make_branch_and_tree('.')
66
65
self.build_tree(['inertiatic/', 'inertiatic/esp'])
67
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
68
self.run_bzr('add inertiatic/esp')
69
self.assertEquals(self.run_bzr('unknowns')[0], '')
66
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
67
self.run_bzr('add', 'inertiatic/esp')
68
self.assertEquals(self.capture('unknowns'), '')
71
70
# Multiple unversioned parents
72
71
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
73
self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
74
self.run_bzr('add veil/cerpin/taxt')
75
self.assertEquals(self.run_bzr('unknowns')[0], '')
72
self.assertEquals(self.capture('unknowns'), 'veil\n')
73
self.run_bzr('add', 'veil/cerpin/taxt')
74
self.assertEquals(self.capture('unknowns'), '')
77
76
# Check whacky paths work
78
77
self.build_tree(['cicatriz/', 'cicatriz/esp'])
79
self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
80
self.run_bzr('add inertiatic/../cicatriz/esp')
81
self.assertEquals(self.run_bzr('unknowns')[0], '')
78
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
79
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
80
self.assertEquals(self.capture('unknowns'), '')
83
82
def test_add_in_versioned(self):
84
83
"""Try to add a file in a versioned directory.
86
85
"bzr add" should do this happily.
88
tree = self.make_branch_and_tree('.')
89
88
self.build_tree(['inertiatic/', 'inertiatic/esp'])
90
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
91
self.run_bzr('add --no-recurse inertiatic')
92
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
93
self.run_bzr('add inertiatic/esp')
94
self.assertEquals(self.run_bzr('unknowns')[0], '')
89
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
90
self.run_bzr('add', '--no-recurse', 'inertiatic')
91
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
92
self.run_bzr('add', 'inertiatic/esp')
93
self.assertEquals(self.capture('unknowns'), '')
96
95
def test_subdir_add(self):
97
96
"""Add in subdirectory should add only things from there down"""
126
125
# add from the parent directory should pick up all file names
128
127
self.run_bzr('add')
129
self.assertEquals(self.run_bzr('unknowns')[0], '')
128
self.assertEquals(self.capture('unknowns'), '')
130
129
self.run_bzr('check')
132
131
def test_add_missing(self):
133
132
"""bzr add foo where foo is missing should error."""
134
133
self.make_branch_and_tree('.')
135
self.run_bzr('add missing-file', retcode=3)
134
self.run_bzr('add', 'missing-file', retcode=3)
137
136
def test_add_from(self):
138
137
base_tree = self.make_branch_and_tree('base')
144
143
self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
147
out, err = self.run_bzr('add --file-ids-from ../base')
146
out, err = self.run_bzr('add', '--file-ids-from', '../base')
148
147
self.assertEqual('', err)
149
148
self.assertEqualDiff('added a w/ file id from a\n'
150
149
'added b w/ file id from b\n'
165
164
self.build_tree(['new/c', 'new/d'])
168
out, err = self.run_bzr('add --file-ids-from ../base/b')
167
out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
169
168
self.assertEqual('', err)
170
169
self.assertEqualDiff('added c w/ file id from b/c\n'
171
170
'added d w/ file id from b/d\n',
176
175
self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
178
177
def test_add_dry_run(self):
179
"""Test a dry run add, make sure nothing is added."""
180
wt = self.make_branch_and_tree('.')
181
self.build_tree(['inertiatic/', 'inertiatic/esp'])
182
self.assertEqual(list(wt.unknowns()), ['inertiatic'])
183
self.run_bzr('add --dry-run')
184
self.assertEqual(list(wt.unknowns()), ['inertiatic'])
178
# ensure that --dry-run actually don't add anything
179
base_tree = self.make_branch_and_tree('.')
180
self.build_tree(['spam'])
181
out = self.run_bzr_captured(['add', '--dry-run'], retcode=0)[0]
182
self.assertEquals('added spam\n', out)
183
out = self.run_bzr_captured(['added'], retcode=0)[0]
184
self.assertEquals('', out)
186
186
def test_add_control_dir(self):
187
187
"""The control dir and its content should be refused."""
188
188
self.make_branch_and_tree('.')
189
err = self.run_bzr('add .bzr', retcode=3)[1]
189
err = self.run_bzr('add', '.bzr', retcode=3)[1]
190
190
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
191
err = self.run_bzr('add .bzr/README', retcode=3)[1]
191
err = self.run_bzr('add', '.bzr/README', retcode=3)[1]
192
192
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
193
193
self.build_tree(['.bzr/crescent'])
194
err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
194
err = self.run_bzr('add', '.bzr/crescent', retcode=3)[1]
195
195
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
197
def test_add_with_wildcards(self):
198
self.requireFeature(NeedsGlobExpansionFeature)
199
self.make_branch_and_tree('.')
200
self.build_tree(['a1', 'a2', 'b', 'c33'])
201
self.run_bzr(['add', 'a?', 'c*'])
202
self.assertEquals(self.run_bzr('unknowns')[0], 'b\n')
204
def test_add_with_wildcards_unicode(self):
205
self.requireFeature(NeedsGlobExpansionFeature)
206
self.make_branch_and_tree('.')
207
self.build_tree([u'\u1234A', u'\u1235A', u'\u1235AA', 'cc'])
208
self.run_bzr(['add', u'\u1234?', u'\u1235*'])
209
self.assertEquals(self.run_bzr('unknowns')[0], 'cc\n')