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