/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006, 2007, 2009, 2010, 2011 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
16
#
17
18
"""Tests of the 'bzr add' command."""
19
20
import os
21
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
22
from bzrlib import (
23
    osutils,
24
    tests,
4163.2.2 by Ian Clatworthy
use multiply_tests rather than subclassing
25
    )
5346.3.1 by Martin Pool
* `PathNotChild` should not give a traceback.
26
from bzrlib.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
27
    features,
5346.3.1 by Martin Pool
* `PathNotChild` should not give a traceback.
28
    script,
29
    )
5559.2.2 by Martin Pool
Change to using standard load_tests_apply_scenarios.
30
from bzrlib.tests.scenarios import load_tests_apply_scenarios
31
32
33
load_tests = load_tests_apply_scenarios
34
35
36
class TestAdd(tests.TestCaseWithTransport):
37
4163.2.2 by Ian Clatworthy
use multiply_tests rather than subclassing
38
    scenarios = [
39
        ('pre-views', {'branch_tree_format': 'pack-0.92'}),
5546.1.1 by Andrew Bennetts
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.
40
        ('view-aware', {'branch_tree_format': '2a'}),
4163.2.2 by Ian Clatworthy
use multiply_tests rather than subclassing
41
        ]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
42
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
43
    def make_branch_and_tree(self, dir):
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
44
        return super(TestAdd, self).make_branch_and_tree(
45
            dir, format=self.branch_tree_format)
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
46
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
47
    def test_add_reports(self):
48
        """add command prints the names of added files."""
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
49
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
50
        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.
51
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
52
        out = self.run_bzr('add')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
53
        # the ordering is not defined at the moment
54
        results = sorted(out.rstrip('\n').split('\n'))
4595.1.1 by Jason Spashett
Further tweaks to bzr add
55
        self.assertEquals(['adding .bzrignore',
3985.2.1 by Daniel Watkins
Updated tests for new behaviour.
56
                           'adding dir',
57
                           'adding dir/sub.txt',
4595.1.1 by Jason Spashett
Further tweaks to bzr add
58
                           'adding top.txt'],
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
59
                          results)
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
60
        out = self.run_bzr('add -v')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
61
        results = sorted(out.rstrip('\n').split('\n'))
4595.1.1 by Jason Spashett
Further tweaks to bzr add
62
        self.assertEquals(['ignored CVS matching "CVS"'],
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
63
                          results)
64
65
    def test_add_quiet_is(self):
66
        """add -q does not print the names of added files."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
67
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
68
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
69
        out = self.run_bzr('add -q')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
70
        # the ordering is not defined at the moment
71
        results = sorted(out.rstrip('\n').split('\n'))
72
        self.assertEquals([''], results)
73
74
    def test_add_in_unversioned(self):
75
        """Try to add a file in an unversioned directory.
76
77
        "bzr add" should add the parent(s) as necessary.
78
        """
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
79
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
80
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
81
        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
82
        self.run_bzr('add inertiatic/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
83
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
84
85
        # Multiple unversioned parents
86
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
87
        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
88
        self.run_bzr('add veil/cerpin/taxt')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
89
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
90
91
        # Check whacky paths work
92
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
93
        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
94
        self.run_bzr('add inertiatic/../cicatriz/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
95
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
96
97
    def test_add_in_versioned(self):
98
        """Try to add a file in a versioned directory.
99
100
        "bzr add" should do this happily.
101
        """
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
102
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
103
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
104
        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
105
        self.run_bzr('add --no-recurse inertiatic')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
106
        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
107
        self.run_bzr('add inertiatic/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
108
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
109
110
    def test_subdir_add(self):
111
        """Add in subdirectory should add only things from there down"""
112
        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.
113
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
114
        eq = self.assertEqual
1836.1.16 by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail.
115
        ass = self.assertTrue
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
116
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
117
        t = self.make_branch_and_tree('.')
118
        b = t.branch
119
        self.build_tree(['src/', 'README'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
120
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
121
        eq(sorted(t.unknowns()),
122
           ['README', 'src'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
123
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
124
        self.run_bzr('add src')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
125
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
126
        self.build_tree(['src/foo.c'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
127
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
128
        # add with no arguments in a subdirectory gets only files below that
129
        # subdirectory
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
130
        self.run_bzr('add', working_dir='src')
131
        self.assertEquals('README\n',
132
                          self.run_bzr('unknowns', working_dir='src')[0])
2255.2.176 by Martin Pool
Merge dirstate and some small cleanups
133
        # reopen to see the new changes
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
134
        t = t.bzrdir.open_workingtree('src')
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
135
        versioned = [path for path, entry in t.iter_entries_by_dir()]
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
136
        self.assertEquals(versioned, ['', 'src', 'src/foo.c'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
137
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
138
        # 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.
139
        self.run_bzr('add')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
140
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
141
        self.run_bzr('check')
1757.2.1 by Robert Collins
Add an explicit test that adding a missing file barfs.
142
143
    def test_add_missing(self):
144
        """bzr add foo where foo is missing should error."""
145
        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
146
        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
147
148
    def test_add_from(self):
149
        base_tree = self.make_branch_and_tree('base')
150
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
151
        base_tree.add(['a', 'b', 'b/c'])
152
        base_tree.commit('foo')
153
154
        new_tree = self.make_branch_and_tree('new')
155
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
156
157
        os.chdir('new')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
158
        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
159
        self.assertEqual('', err)
3985.2.1 by Daniel Watkins
Updated tests for new behaviour.
160
        self.assertEqualDiff('adding a w/ file id from a\n'
161
                             'adding b w/ file id from b\n'
4075.1.1 by Robert Collins
add should not print 'add completed' unnecessarily.
162
                             'adding b/c w/ file id from b/c\n',
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
163
                             out)
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
164
        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
165
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
166
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
167
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
168
169
    def test_add_from_subdir(self):
170
        base_tree = self.make_branch_and_tree('base')
171
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
172
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
173
        base_tree.commit('foo')
174
175
        new_tree = self.make_branch_and_tree('new')
176
        self.build_tree(['new/c', 'new/d'])
177
178
        os.chdir('new')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
179
        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
180
        self.assertEqual('', err)
3985.2.1 by Daniel Watkins
Updated tests for new behaviour.
181
        self.assertEqualDiff('adding c w/ file id from b/c\n'
4075.1.1 by Robert Collins
add should not print 'add completed' unnecessarily.
182
                             'adding d w/ file id from b/d\n',
1911.3.2 by John Arbash Meinel
Adding the AddFromBaseAction, which tries to reuse file ids from another tree
183
                             out)
184
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
185
        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
186
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
187
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
1928.1.1 by Alexander Belchenko
blackbox test for 'bzr add --dry-run'
188
189
    def test_add_dry_run(self):
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
190
        """Test a dry run add, make sure nothing is added."""
191
        wt = self.make_branch_and_tree('.')
192
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
193
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
194
        self.run_bzr('add --dry-run')
195
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
196
197
    def test_add_control_dir(self):
198
        """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).
199
        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
200
        err = self.run_bzr('add .bzr', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
201
        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
202
        err = self.run_bzr('add .bzr/README', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
203
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
204
        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
205
        err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
206
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
2617.5.3 by Kuno Meyer
Blackbox test for adding with wildcards (Win32).
207
4301.1.1 by Geoff Bache
Fixing bug 183831, where 'bzr add' fails with a python stack if the path contains a symbolic link
208
    def test_add_via_symlink(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
209
        self.requireFeature(features.SymlinkFeature)
4301.1.1 by Geoff Bache
Fixing bug 183831, where 'bzr add' fails with a python stack if the path contains a symbolic link
210
        self.make_branch_and_tree('source')
211
        self.build_tree(['source/top.txt'])
212
        os.symlink('source', 'link')
213
        out = self.run_bzr(['add', 'link/top.txt'])[0]
214
        self.assertEquals(out, 'adding top.txt\n')
215
216
    def test_add_symlink_to_abspath(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
217
        self.requireFeature(features.SymlinkFeature)
4301.2.4 by Aaron Bentley
Further cleanups
218
        self.make_branch_and_tree('tree')
219
        os.symlink(osutils.abspath('target'), 'tree/link')
220
        out = self.run_bzr(['add', 'tree/link'])[0]
4301.1.1 by Geoff Bache
Fixing bug 183831, where 'bzr add' fails with a python stack if the path contains a symbolic link
221
        self.assertEquals(out, 'adding link\n')
4634.169.1 by Martin
Don't use normalizepath in smart_add unless symlinks are supported which avoids unicode breakage on windows
222
5346.3.1 by Martin Pool
* `PathNotChild` should not give a traceback.
223
    def test_add_not_child(self):
224
        # https://bugs.launchpad.net/bzr/+bug/98735
225
        sr = script.ScriptRunner()
226
        self.make_branch_and_tree('tree1')
227
        self.make_branch_and_tree('tree2')
228
        self.build_tree(['tree1/a', 'tree2/b'])
229
        sr.run_script(self, '''
230
        $ bzr add tree1/a tree2/b
231
        2>bzr: ERROR: Path "...tree2/b" is not a child of path "...tree1"
232
        ''')
5573.1.1 by Martin
Merge 2.2 for fixes to lp:686611 and lp:687653
233
4634.169.1 by Martin
Don't use normalizepath in smart_add unless symlinks are supported which avoids unicode breakage on windows
234
    def test_add_multiple_files_in_unicode_cwd(self):
235
        """Adding multiple files in a non-ascii cwd, see lp:686611"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
236
        self.requireFeature(features.UnicodeFilenameFeature)
4634.169.1 by Martin
Don't use normalizepath in smart_add unless symlinks are supported which avoids unicode breakage on windows
237
        self.make_branch_and_tree(u"\xA7")
238
        self.build_tree([u"\xA7/a", u"\xA7/b"])
239
        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, "")
6046.2.1 by Shannon Weyrick
Add support for skipping large files during add, based on configurable threshold (default 1M). Fixes bug #54624
242
        
243
    def test_add_skip_large_files(self):
6046.2.4 by Shannon Weyrick
Change AddAction interface to include a method for deciding whether to
244
        """Test skipping files larger than add.maximum_file_size"""
6046.2.1 by Shannon Weyrick
Add support for skipping large files during add, based on configurable threshold (default 1M). Fixes bug #54624
245
        tree = self.make_branch_and_tree('.')
6046.2.9 by Shannon Weyrick
Make it explicit in docs that large file skips happen only in recursive mode. Add test.
246
        self.build_tree(['small.txt', 'big.txt', 'big2.txt'])
6046.2.1 by Shannon Weyrick
Add support for skipping large files during add, based on configurable threshold (default 1M). Fixes bug #54624
247
        self.build_tree_contents([('small.txt', '0\n')])
248
        self.build_tree_contents([('big.txt', '01234567890123456789\n')])
6046.2.9 by Shannon Weyrick
Make it explicit in docs that large file skips happen only in recursive mode. Add test.
249
        self.build_tree_contents([('big2.txt', '01234567890123456789\n')])
6046.2.4 by Shannon Weyrick
Change AddAction interface to include a method for deciding whether to
250
        tree.branch.get_config().set_user_option('add.maximum_file_size', 5)
6046.2.1 by Shannon Weyrick
Add support for skipping large files during add, based on configurable threshold (default 1M). Fixes bug #54624
251
        out = self.run_bzr('add')[0]
252
        results = sorted(out.rstrip('\n').split('\n'))
253
        self.assertEquals(['adding small.txt'], 
254
                          results)
6046.2.9 by Shannon Weyrick
Make it explicit in docs that large file skips happen only in recursive mode. Add test.
255
        # named items never skipped, even if over max
256
        out, err = self.run_bzr(["add", "big2.txt"])
257
        results = sorted(out.rstrip('\n').split('\n'))
258
        self.assertEquals(['adding big2.txt'], 
259
                          results)
260
        self.assertEquals(err, "")
6046.2.4 by Shannon Weyrick
Change AddAction interface to include a method for deciding whether to
261
        tree.branch.get_config().set_user_option('add.maximum_file_size', 30)
6046.2.1 by Shannon Weyrick
Add support for skipping large files during add, based on configurable threshold (default 1M). Fixes bug #54624
262
        out = self.run_bzr('add')[0]
263
        results = sorted(out.rstrip('\n').split('\n'))
264
        self.assertEquals(['adding big.txt'], 
265
                          results)