110
112
self.build_tree(['src/foo.c'])
114
# add with no arguments in a subdirectory gets only files below that
113
117
self.run_bzr('add')
115
118
self.assertEquals(self.capture('unknowns'), 'README\n')
116
eq(len(t.read_working_inventory()), 3)
119
# reopen to see the new changes
120
t = t.bzrdir.open_workingtree()
121
versioned = [path for path, entry in t.iter_entries_by_dir()]
122
self.assertEquals(versioned,
123
['', 'src', 'src/foo.c'])
125
# add from the parent directory should pick up all file names
119
127
self.run_bzr('add')
120
128
self.assertEquals(self.capture('unknowns'), '')
121
129
self.run_bzr('check')
131
def test_add_missing(self):
132
"""bzr add foo where foo is missing should error."""
133
self.make_branch_and_tree('.')
134
self.run_bzr('add', 'missing-file', retcode=3)
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')
142
new_tree = self.make_branch_and_tree('new')
143
self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
146
out, err = self.run_bzr('add', '--file-ids-from', '../base')
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',
152
new_tree = new_tree.bzrdir.open_workingtree()
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'))
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')
163
new_tree = self.make_branch_and_tree('new')
164
self.build_tree(['new/c', 'new/d'])
167
out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
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',
173
new_tree = new_tree.bzrdir.open_workingtree()
174
self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
175
self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
177
def test_add_dry_run(self):
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
def test_add_control_dir(self):
187
"""The control dir and its content should be refused."""
188
self.make_branch_and_tree('.')
189
err = self.run_bzr('add', '.bzr', retcode=3)[1]
190
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
191
err = self.run_bzr('add', '.bzr/README', retcode=3)[1]
192
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
193
self.build_tree(['.bzr/crescent'])
194
err = self.run_bzr('add', '.bzr/crescent', retcode=3)[1]
195
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')