1
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
51
52
out = self.run_bzr('add')[0]
52
53
# the ordering is not defined at the moment
53
54
results = sorted(out.rstrip('\n').split('\n'))
54
self.assertEquals(['adding .bzrignore',
55
self.assertEqual(['adding .bzrignore',
56
57
'adding dir/sub.txt',
59
60
out = self.run_bzr('add -v')[0]
60
61
results = sorted(out.rstrip('\n').split('\n'))
61
self.assertEquals(['ignored CVS matching "CVS"'],
62
self.assertEqual(['ignored CVS matching "CVS"'],
64
65
def test_add_quiet_is(self):
68
69
out = self.run_bzr('add -q')[0]
69
70
# the ordering is not defined at the moment
70
71
results = sorted(out.rstrip('\n').split('\n'))
71
self.assertEquals([''], results)
72
self.assertEqual([''], results)
73
74
def test_add_in_unversioned(self):
74
75
"""Try to add a file in an unversioned directory.
78
79
tree = self.make_branch_and_tree('.')
79
80
self.build_tree(['inertiatic/', 'inertiatic/esp'])
80
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
81
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
81
82
self.run_bzr('add inertiatic/esp')
82
self.assertEquals(self.run_bzr('unknowns')[0], '')
83
self.assertEqual(self.run_bzr('unknowns')[0], '')
84
85
# Multiple unversioned parents
85
86
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
86
self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
87
self.assertEqual(self.run_bzr('unknowns')[0], 'veil\n')
87
88
self.run_bzr('add veil/cerpin/taxt')
88
self.assertEquals(self.run_bzr('unknowns')[0], '')
89
self.assertEqual(self.run_bzr('unknowns')[0], '')
90
91
# Check whacky paths work
91
92
self.build_tree(['cicatriz/', 'cicatriz/esp'])
92
self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
93
self.assertEqual(self.run_bzr('unknowns')[0], 'cicatriz\n')
93
94
self.run_bzr('add inertiatic/../cicatriz/esp')
94
self.assertEquals(self.run_bzr('unknowns')[0], '')
95
self.assertEqual(self.run_bzr('unknowns')[0], '')
97
def test_add_no_recurse(self):
98
tree = self.make_branch_and_tree('.')
99
self.build_tree(['inertiatic/', 'inertiatic/esp'])
100
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
101
self.run_bzr('add -N inertiatic')
102
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
96
104
def test_add_in_versioned(self):
97
105
"""Try to add a file in a versioned directory.
101
109
tree = self.make_branch_and_tree('.')
102
110
self.build_tree(['inertiatic/', 'inertiatic/esp'])
103
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
111
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
104
112
self.run_bzr('add --no-recurse inertiatic')
105
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
113
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
106
114
self.run_bzr('add inertiatic/esp')
107
self.assertEquals(self.run_bzr('unknowns')[0], '')
115
self.assertEqual(self.run_bzr('unknowns')[0], '')
109
117
def test_subdir_add(self):
110
118
"""Add in subdirectory should add only things from there down"""
111
from bzrlib.workingtree import WorkingTree
113
119
eq = self.assertEqual
114
120
ass = self.assertTrue
127
133
# add with no arguments in a subdirectory gets only files below that
129
135
self.run_bzr('add', working_dir='src')
130
self.assertEquals('README\n',
136
self.assertEqual('README\n',
131
137
self.run_bzr('unknowns', working_dir='src')[0])
132
138
# reopen to see the new changes
133
139
t = t.bzrdir.open_workingtree('src')
134
140
versioned = [path for path, entry in t.iter_entries_by_dir()]
135
self.assertEquals(versioned, ['', 'src', 'src/foo.c'])
141
self.assertEqual(versioned, ['', 'src', 'src/foo.c'])
137
143
# add from the parent directory should pick up all file names
138
144
self.run_bzr('add')
139
self.assertEquals(self.run_bzr('unknowns')[0], '')
145
self.assertEqual(self.run_bzr('unknowns')[0], '')
140
146
self.run_bzr('check')
142
148
def test_add_missing(self):
153
159
new_tree = self.make_branch_and_tree('new')
154
160
self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
157
out, err = self.run_bzr('add --file-ids-from ../base')
162
out, err = self.run_bzr('add --file-ids-from ../base',
158
164
self.assertEqual('', err)
159
165
self.assertEqualDiff('adding a w/ file id from a\n'
160
166
'adding b w/ file id from b\n'
174
180
new_tree = self.make_branch_and_tree('new')
175
181
self.build_tree(['new/c', 'new/d'])
178
out, err = self.run_bzr('add --file-ids-from ../base/b')
183
out, err = self.run_bzr('add --file-ids-from ../base/b',
179
185
self.assertEqual('', err)
180
186
self.assertEqualDiff('adding c w/ file id from b/c\n'
181
187
'adding d w/ file id from b/d\n',
184
new_tree = new_tree.bzrdir.open_workingtree()
190
new_tree = new_tree.bzrdir.open_workingtree('new')
185
191
self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
186
192
self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
205
211
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
207
213
def test_add_via_symlink(self):
208
self.requireFeature(tests.SymlinkFeature)
214
self.requireFeature(features.SymlinkFeature)
209
215
self.make_branch_and_tree('source')
210
216
self.build_tree(['source/top.txt'])
211
217
os.symlink('source', 'link')
212
218
out = self.run_bzr(['add', 'link/top.txt'])[0]
213
self.assertEquals(out, 'adding top.txt\n')
219
self.assertEqual(out, 'adding top.txt\n')
215
221
def test_add_symlink_to_abspath(self):
216
self.requireFeature(tests.SymlinkFeature)
222
self.requireFeature(features.SymlinkFeature)
217
223
self.make_branch_and_tree('tree')
218
224
os.symlink(osutils.abspath('target'), 'tree/link')
219
225
out = self.run_bzr(['add', 'tree/link'])[0]
220
self.assertEquals(out, 'adding link\n')
226
self.assertEqual(out, 'adding link\n')
222
228
def test_add_not_child(self):
223
229
# https://bugs.launchpad.net/bzr/+bug/98735
233
239
def test_add_multiple_files_in_unicode_cwd(self):
234
240
"""Adding multiple files in a non-ascii cwd, see lp:686611"""
235
self.requireFeature(tests.UnicodeFilename)
241
self.requireFeature(features.UnicodeFilenameFeature)
236
242
self.make_branch_and_tree(u"\xA7")
237
243
self.build_tree([u"\xA7/a", u"\xA7/b"])
238
244
out, err = self.run_bzr(["add", "a", "b"], working_dir=u"\xA7")
239
self.assertEquals(out, "adding a\n" "adding b\n")
240
self.assertEquals(err, "")
245
self.assertEqual(out, "adding a\n" "adding b\n")
246
self.assertEqual(err, "")
248
def test_add_skip_large_files(self):
249
"""Test skipping files larger than add.maximum_file_size"""
250
tree = self.make_branch_and_tree('.')
251
self.build_tree(['small.txt', 'big.txt', 'big2.txt'])
252
self.build_tree_contents([('small.txt', '0\n')])
253
self.build_tree_contents([('big.txt', '01234567890123456789\n')])
254
self.build_tree_contents([('big2.txt', '01234567890123456789\n')])
255
tree.branch.get_config_stack().set('add.maximum_file_size', 5)
256
out = self.run_bzr('add')[0]
257
results = sorted(out.rstrip('\n').split('\n'))
258
self.assertEqual(['adding small.txt'], results)
259
# named items never skipped, even if over max
260
out, err = self.run_bzr(["add", "big2.txt"])
261
results = sorted(out.rstrip('\n').split('\n'))
262
self.assertEqual(['adding big2.txt'], results)
263
self.assertEqual("", err)
264
tree.branch.get_config_stack().set('add.maximum_file_size', 30)
265
out = self.run_bzr('add')[0]
266
results = sorted(out.rstrip('\n').split('\n'))
267
self.assertEqual(['adding big.txt'], results)