~bzr-pqm/bzr/bzr.dev

4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2006, 2007, 2009, 2010 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 (
27
    script,
28
    )
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
29
30
4163.2.2 by Ian Clatworthy
use multiply_tests rather than subclassing
31
def load_tests(standard_tests, module, loader):
32
    """Parameterize tests for view-aware vs not."""
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
33
    to_adapt, result = tests.split_suite_by_condition(
34
        standard_tests, tests.condition_isinstance(TestAdd))
4163.2.2 by Ian Clatworthy
use multiply_tests rather than subclassing
35
    scenarios = [
36
        ('pre-views', {'branch_tree_format': 'pack-0.92'}),
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
37
        ('view-aware', {'branch_tree_format': 'development6-rich-root'}),
4163.2.2 by Ian Clatworthy
use multiply_tests rather than subclassing
38
        ]
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
39
    return tests.multiply_tests(to_adapt, scenarios, result)
40
41
42
class TestAdd(tests.TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
43
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
44
    def make_branch_and_tree(self, dir):
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
45
        return super(TestAdd, self).make_branch_and_tree(
46
            dir, format=self.branch_tree_format)
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
47
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
48
    def test_add_reports(self):
49
        """add command prints the names of added files."""
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
50
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
51
        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.
52
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
53
        out = self.run_bzr('add')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
54
        # the ordering is not defined at the moment
55
        results = sorted(out.rstrip('\n').split('\n'))
4595.1.1 by Jason Spashett
Further tweaks to bzr add
56
        self.assertEquals(['adding .bzrignore',
3985.2.1 by Daniel Watkins
Updated tests for new behaviour.
57
                           'adding dir',
58
                           'adding dir/sub.txt',
4595.1.1 by Jason Spashett
Further tweaks to bzr add
59
                           'adding top.txt'],
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
60
                          results)
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
61
        out = self.run_bzr('add -v')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
62
        results = sorted(out.rstrip('\n').split('\n'))
4595.1.1 by Jason Spashett
Further tweaks to bzr add
63
        self.assertEquals(['ignored CVS matching "CVS"'],
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
64
                          results)
65
66
    def test_add_quiet_is(self):
67
        """add -q does not print the names of added files."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
68
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
69
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
2581.1.2 by Martin Pool
Remove unnecessary retcode=0 to run_bzr calls
70
        out = self.run_bzr('add -q')[0]
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
71
        # the ordering is not defined at the moment
72
        results = sorted(out.rstrip('\n').split('\n'))
73
        self.assertEquals([''], results)
74
75
    def test_add_in_unversioned(self):
76
        """Try to add a file in an unversioned directory.
77
78
        "bzr add" should add the parent(s) as necessary.
79
        """
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
80
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
81
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
82
        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
83
        self.run_bzr('add inertiatic/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
84
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
85
86
        # Multiple unversioned parents
87
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
88
        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
89
        self.run_bzr('add veil/cerpin/taxt')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
90
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
91
92
        # Check whacky paths work
93
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
94
        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
95
        self.run_bzr('add inertiatic/../cicatriz/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
96
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
97
98
    def test_add_in_versioned(self):
99
        """Try to add a file in a versioned directory.
100
101
        "bzr add" should do this happily.
102
        """
2664.3.1 by Daniel Watkins
tests.blackbox.test_add now uses internals where appropriate.
103
        tree = self.make_branch_and_tree('.')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
104
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
105
        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
106
        self.run_bzr('add --no-recurse inertiatic')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
107
        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
108
        self.run_bzr('add inertiatic/esp')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
109
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
110
111
    def test_subdir_add(self):
112
        """Add in subdirectory should add only things from there down"""
113
        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.
114
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
115
        eq = self.assertEqual
1836.1.16 by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail.
116
        ass = self.assertTrue
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
117
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
118
        t = self.make_branch_and_tree('.')
119
        b = t.branch
120
        self.build_tree(['src/', 'README'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
121
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
122
        eq(sorted(t.unknowns()),
123
           ['README', 'src'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
124
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
125
        self.run_bzr('add src')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
126
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
127
        self.build_tree(['src/foo.c'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
128
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
129
        # add with no arguments in a subdirectory gets only files below that
130
        # subdirectory
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
131
        self.run_bzr('add', working_dir='src')
132
        self.assertEquals('README\n',
133
                          self.run_bzr('unknowns', working_dir='src')[0])
2255.2.176 by Martin Pool
Merge dirstate and some small cleanups
134
        # reopen to see the new changes
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
135
        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
136
        versioned = [path for path, entry in t.iter_entries_by_dir()]
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
137
        self.assertEquals(versioned, ['', 'src', 'src/foo.c'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
138
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
139
        # 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.
140
        self.run_bzr('add')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
141
        self.assertEquals(self.run_bzr('unknowns')[0], '')
1711.1.3 by Robert Collins
Add new test_add file - should have been in last commit.
142
        self.run_bzr('check')
1757.2.1 by Robert Collins
Add an explicit test that adding a missing file barfs.
143
144
    def test_add_missing(self):
145
        """bzr add foo where foo is missing should error."""
146
        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
147
        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
148
149
    def test_add_from(self):
150
        base_tree = self.make_branch_and_tree('base')
151
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
152
        base_tree.add(['a', 'b', 'b/c'])
153
        base_tree.commit('foo')
154
155
        new_tree = self.make_branch_and_tree('new')
156
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
157
158
        os.chdir('new')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
159
        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
160
        self.assertEqual('', err)
3985.2.1 by Daniel Watkins
Updated tests for new behaviour.
161
        self.assertEqualDiff('adding a w/ file id from a\n'
162
                             'adding b w/ file id from b\n'
4075.1.1 by Robert Collins
add should not print 'add completed' unnecessarily.
163
                             '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
164
                             out)
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
165
        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
166
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
167
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
168
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
169
170
    def test_add_from_subdir(self):
171
        base_tree = self.make_branch_and_tree('base')
172
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
173
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
174
        base_tree.commit('foo')
175
176
        new_tree = self.make_branch_and_tree('new')
177
        self.build_tree(['new/c', 'new/d'])
178
179
        os.chdir('new')
2530.3.3 by Martin Pool
Clean up some callers that use varargs syntax for run_bzr, but don't
180
        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
181
        self.assertEqual('', err)
3985.2.1 by Daniel Watkins
Updated tests for new behaviour.
182
        self.assertEqualDiff('adding c w/ file id from b/c\n'
4075.1.1 by Robert Collins
add should not print 'add completed' unnecessarily.
183
                             '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
184
                             out)
185
2255.2.171 by Martin Pool
Fix up blackbox test_add to avoid depending on inventory not being held in memory
186
        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
187
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
188
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
1928.1.1 by Alexander Belchenko
blackbox test for 'bzr add --dry-run'
189
190
    def test_add_dry_run(self):
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
191
        """Test a dry run add, make sure nothing is added."""
192
        wt = self.make_branch_and_tree('.')
193
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
194
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
195
        self.run_bzr('add --dry-run')
196
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
197
198
    def test_add_control_dir(self):
199
        """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).
200
        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
201
        err = self.run_bzr('add .bzr', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
202
        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
203
        err = self.run_bzr('add .bzr/README', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
204
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
205
        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
206
        err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
2279.5.1 by Matthias Rahlf
FastPath objects can now be printed nicely
207
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
2617.5.3 by Kuno Meyer
Blackbox test for adding with wildcards (Win32).
208
4301.1.1 by Geoff Bache
Fixing bug 183831, where 'bzr add' fails with a python stack if the path contains a symbolic link
209
    def test_add_via_symlink(self):
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
210
        self.requireFeature(tests.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
211
        self.make_branch_and_tree('source')
212
        self.build_tree(['source/top.txt'])
213
        os.symlink('source', 'link')
214
        out = self.run_bzr(['add', 'link/top.txt'])[0]
215
        self.assertEquals(out, 'adding top.txt\n')
216
217
    def test_add_symlink_to_abspath(self):
5012.1.1 by Vincent Ladeuil
Fix imports in blackbox/test_add.py.
218
        self.requireFeature(tests.SymlinkFeature)
4301.2.4 by Aaron Bentley
Further cleanups
219
        self.make_branch_and_tree('tree')
220
        os.symlink(osutils.abspath('target'), 'tree/link')
221
        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
222
        self.assertEquals(out, 'adding link\n')
5346.3.1 by Martin Pool
* `PathNotChild` should not give a traceback.
223
224
    def test_add_not_child(self):
225
        # https://bugs.launchpad.net/bzr/+bug/98735
226
        sr = script.ScriptRunner()
227
        self.make_branch_and_tree('tree1')
228
        self.make_branch_and_tree('tree2')
229
        self.build_tree(['tree1/a', 'tree2/b'])
230
        sr.run_script(self, '''
231
        $ bzr add tree1/a tree2/b
232
        2>bzr: ERROR: Path "...tree2/b" is not a child of path "...tree1"
233
        ''')