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
52
52
out = self.run_bzr('add')[0]
53
53
# the ordering is not defined at the moment
54
54
results = sorted(out.rstrip('\n').split('\n'))
55
self.assertEquals(['adding .bzrignore',
55
self.assertEqual(['adding .bzrignore',
57
57
'adding dir/sub.txt',
60
60
out = self.run_bzr('add -v')[0]
61
61
results = sorted(out.rstrip('\n').split('\n'))
62
self.assertEquals(['ignored CVS matching "CVS"'],
62
self.assertEqual(['ignored CVS matching "CVS"'],
65
65
def test_add_quiet_is(self):
69
69
out = self.run_bzr('add -q')[0]
70
70
# the ordering is not defined at the moment
71
71
results = sorted(out.rstrip('\n').split('\n'))
72
self.assertEquals([''], results)
72
self.assertEqual([''], results)
74
74
def test_add_in_unversioned(self):
75
75
"""Try to add a file in an unversioned directory.
79
79
tree = self.make_branch_and_tree('.')
80
80
self.build_tree(['inertiatic/', 'inertiatic/esp'])
81
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
81
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
82
82
self.run_bzr('add inertiatic/esp')
83
self.assertEquals(self.run_bzr('unknowns')[0], '')
83
self.assertEqual(self.run_bzr('unknowns')[0], '')
85
85
# Multiple unversioned parents
86
86
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
87
self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
87
self.assertEqual(self.run_bzr('unknowns')[0], 'veil\n')
88
88
self.run_bzr('add veil/cerpin/taxt')
89
self.assertEquals(self.run_bzr('unknowns')[0], '')
89
self.assertEqual(self.run_bzr('unknowns')[0], '')
91
91
# Check whacky paths work
92
92
self.build_tree(['cicatriz/', 'cicatriz/esp'])
93
self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
93
self.assertEqual(self.run_bzr('unknowns')[0], 'cicatriz\n')
94
94
self.run_bzr('add inertiatic/../cicatriz/esp')
95
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')
97
104
def test_add_in_versioned(self):
98
105
"""Try to add a file in a versioned directory.
102
109
tree = self.make_branch_and_tree('.')
103
110
self.build_tree(['inertiatic/', 'inertiatic/esp'])
104
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
111
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic\n')
105
112
self.run_bzr('add --no-recurse inertiatic')
106
self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
113
self.assertEqual(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
107
114
self.run_bzr('add inertiatic/esp')
108
self.assertEquals(self.run_bzr('unknowns')[0], '')
115
self.assertEqual(self.run_bzr('unknowns')[0], '')
110
117
def test_subdir_add(self):
111
118
"""Add in subdirectory should add only things from there down"""
112
from bzrlib.workingtree import WorkingTree
114
119
eq = self.assertEqual
115
120
ass = self.assertTrue
128
133
# add with no arguments in a subdirectory gets only files below that
130
135
self.run_bzr('add', working_dir='src')
131
self.assertEquals('README\n',
136
self.assertEqual('README\n',
132
137
self.run_bzr('unknowns', working_dir='src')[0])
133
138
# reopen to see the new changes
134
139
t = t.bzrdir.open_workingtree('src')
135
140
versioned = [path for path, entry in t.iter_entries_by_dir()]
136
self.assertEquals(versioned, ['', 'src', 'src/foo.c'])
141
self.assertEqual(versioned, ['', 'src', 'src/foo.c'])
138
143
# add from the parent directory should pick up all file names
139
144
self.run_bzr('add')
140
self.assertEquals(self.run_bzr('unknowns')[0], '')
145
self.assertEqual(self.run_bzr('unknowns')[0], '')
141
146
self.run_bzr('check')
143
148
def test_add_missing(self):
154
159
new_tree = self.make_branch_and_tree('new')
155
160
self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
158
out, err = self.run_bzr('add --file-ids-from ../base')
162
out, err = self.run_bzr('add --file-ids-from ../base',
159
164
self.assertEqual('', err)
160
165
self.assertEqualDiff('adding a w/ file id from a\n'
161
166
'adding b w/ file id from b\n'
175
180
new_tree = self.make_branch_and_tree('new')
176
181
self.build_tree(['new/c', 'new/d'])
179
out, err = self.run_bzr('add --file-ids-from ../base/b')
183
out, err = self.run_bzr('add --file-ids-from ../base/b',
180
185
self.assertEqual('', err)
181
186
self.assertEqualDiff('adding c w/ file id from b/c\n'
182
187
'adding d w/ file id from b/d\n',
185
new_tree = new_tree.bzrdir.open_workingtree()
190
new_tree = new_tree.bzrdir.open_workingtree('new')
186
191
self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
187
192
self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
211
216
self.build_tree(['source/top.txt'])
212
217
os.symlink('source', 'link')
213
218
out = self.run_bzr(['add', 'link/top.txt'])[0]
214
self.assertEquals(out, 'adding top.txt\n')
219
self.assertEqual(out, 'adding top.txt\n')
216
221
def test_add_symlink_to_abspath(self):
217
222
self.requireFeature(features.SymlinkFeature)
218
223
self.make_branch_and_tree('tree')
219
224
os.symlink(osutils.abspath('target'), 'tree/link')
220
225
out = self.run_bzr(['add', 'tree/link'])[0]
221
self.assertEquals(out, 'adding link\n')
226
self.assertEqual(out, 'adding link\n')
223
228
def test_add_not_child(self):
224
229
# https://bugs.launchpad.net/bzr/+bug/98735
237
242
self.make_branch_and_tree(u"\xA7")
238
243
self.build_tree([u"\xA7/a", u"\xA7/b"])
239
244
out, err = self.run_bzr(["add", "a", "b"], working_dir=u"\xA7")
240
self.assertEquals(out, "adding a\n" "adding b\n")
241
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)