~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_add.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-07 07:52:50 UTC
  • mfrom: (3340.1.1 208418-1.4)
  • Revision ID: pqm@pqm.ubuntu.com-20080407075250-phs53xnslo8boaeo
Return the correct knit serialisation method in _StreamAccess.
        (Andrew Bennetts, Martin Pool, Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
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
20
20
import os
21
21
 
22
22
from bzrlib.tests.blackbox import ExternalBase
 
23
from bzrlib.tests.test_win32utils import NeedsGlobExpansionFeature
23
24
 
24
25
 
25
26
class TestAdd(ExternalBase):
26
27
        
27
28
    def test_add_reports(self):
28
29
        """add command prints the names of added files."""
29
 
        self.runbzr('init')
 
30
        tree = self.make_branch_and_tree('.')
30
31
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
31
32
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
32
 
        out = self.run_bzr_captured(['add'], retcode=0)[0]
 
33
        out = self.run_bzr('add')[0]
33
34
        # the ordering is not defined at the moment
34
35
        results = sorted(out.rstrip('\n').split('\n'))
35
36
        self.assertEquals(['If you wish to add some of these files, please'\
40
41
                           'added top.txt',
41
42
                           'ignored 1 file(s).'],
42
43
                          results)
43
 
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
 
44
        out = self.run_bzr('add -v')[0]
44
45
        results = sorted(out.rstrip('\n').split('\n'))
45
46
        self.assertEquals(['If you wish to add some of these files, please'\
46
47
                           ' add them by name.',
49
50
 
50
51
    def test_add_quiet_is(self):
51
52
        """add -q does not print the names of added files."""
52
 
        self.runbzr('init')
 
53
        tree = self.make_branch_and_tree('.') 
53
54
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
54
 
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
 
55
        out = self.run_bzr('add -q')[0]
55
56
        # the ordering is not defined at the moment
56
57
        results = sorted(out.rstrip('\n').split('\n'))
57
58
        self.assertEquals([''], results)
61
62
 
62
63
        "bzr add" should add the parent(s) as necessary.
63
64
        """
64
 
        self.runbzr('init')
 
65
        tree = self.make_branch_and_tree('.')
65
66
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
66
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
67
 
        self.run_bzr('add', 'inertiatic/esp')
68
 
        self.assertEquals(self.capture('unknowns'), '')
 
67
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
 
68
        self.run_bzr('add inertiatic/esp')
 
69
        self.assertEquals(self.run_bzr('unknowns')[0], '')
69
70
 
70
71
        # Multiple unversioned parents
71
72
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
72
 
        self.assertEquals(self.capture('unknowns'), 'veil\n')
73
 
        self.run_bzr('add', 'veil/cerpin/taxt')
74
 
        self.assertEquals(self.capture('unknowns'), '')
 
73
        self.assertEquals(self.run_bzr('unknowns')[0], 'veil\n')
 
74
        self.run_bzr('add veil/cerpin/taxt')
 
75
        self.assertEquals(self.run_bzr('unknowns')[0], '')
75
76
 
76
77
        # Check whacky paths work
77
78
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
78
 
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
79
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
80
 
        self.assertEquals(self.capture('unknowns'), '')
 
79
        self.assertEquals(self.run_bzr('unknowns')[0], 'cicatriz\n')
 
80
        self.run_bzr('add inertiatic/../cicatriz/esp')
 
81
        self.assertEquals(self.run_bzr('unknowns')[0], '')
81
82
 
82
83
    def test_add_in_versioned(self):
83
84
        """Try to add a file in a versioned directory.
84
85
 
85
86
        "bzr add" should do this happily.
86
87
        """
87
 
        self.runbzr('init')
 
88
        tree = self.make_branch_and_tree('.')
88
89
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
89
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
90
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
91
 
        self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
92
 
        self.run_bzr('add', 'inertiatic/esp')
93
 
        self.assertEquals(self.capture('unknowns'), '')
 
90
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic\n')
 
91
        self.run_bzr('add --no-recurse inertiatic')
 
92
        self.assertEquals(self.run_bzr('unknowns')[0], 'inertiatic/esp\n')
 
93
        self.run_bzr('add inertiatic/esp')
 
94
        self.assertEquals(self.run_bzr('unknowns')[0], '')
94
95
 
95
96
    def test_subdir_add(self):
96
97
        """Add in subdirectory should add only things from there down"""
107
108
        eq(sorted(t.unknowns()),
108
109
           ['README', 'src'])
109
110
        
110
 
        self.run_bzr('add', 'src')
 
111
        self.run_bzr('add src')
111
112
        
112
113
        self.build_tree(['src/foo.c'])
113
114
        
115
116
        # subdirectory
116
117
        chdir('src')
117
118
        self.run_bzr('add')
118
 
        self.assertEquals(self.capture('unknowns'), 'README\n')
 
119
        self.assertEquals(self.run_bzr('unknowns')[0], 'README\n')
119
120
        # reopen to see the new changes
120
121
        t = t.bzrdir.open_workingtree()
121
122
        versioned = [path for path, entry in t.iter_entries_by_dir()]
125
126
        # add from the parent directory should pick up all file names
126
127
        chdir('..')
127
128
        self.run_bzr('add')
128
 
        self.assertEquals(self.capture('unknowns'), '')
 
129
        self.assertEquals(self.run_bzr('unknowns')[0], '')
129
130
        self.run_bzr('check')
130
131
 
131
132
    def test_add_missing(self):
132
133
        """bzr add foo where foo is missing should error."""
133
134
        self.make_branch_and_tree('.')
134
 
        self.run_bzr('add', 'missing-file', retcode=3)
 
135
        self.run_bzr('add missing-file', retcode=3)
135
136
 
136
137
    def test_add_from(self):
137
138
        base_tree = self.make_branch_and_tree('base')
143
144
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
144
145
 
145
146
        os.chdir('new')
146
 
        out, err = self.run_bzr('add', '--file-ids-from', '../base')
 
147
        out, err = self.run_bzr('add --file-ids-from ../base')
147
148
        self.assertEqual('', err)
148
149
        self.assertEqualDiff('added a w/ file id from a\n'
149
150
                             'added b w/ file id from b\n'
164
165
        self.build_tree(['new/c', 'new/d'])
165
166
 
166
167
        os.chdir('new')
167
 
        out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
 
168
        out, err = self.run_bzr('add --file-ids-from ../base/b')
168
169
        self.assertEqual('', err)
169
170
        self.assertEqualDiff('added c w/ file id from b/c\n'
170
171
                             'added d w/ file id from b/d\n',
175
176
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
176
177
 
177
178
    def test_add_dry_run(self):
178
 
        # ensure that --dry-run actually don't add anything
179
 
        base_tree = self.make_branch_and_tree('.')
180
 
        self.build_tree(['spam'])
181
 
        out = self.run_bzr_captured(['add', '--dry-run'], retcode=0)[0]
182
 
        self.assertEquals('added spam\n', out)
183
 
        out = self.run_bzr_captured(['added'], retcode=0)[0]
184
 
        self.assertEquals('', out)
 
179
        """Test a dry run add, make sure nothing is added."""
 
180
        wt = self.make_branch_and_tree('.')
 
181
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
 
182
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
 
183
        self.run_bzr('add --dry-run')
 
184
        self.assertEqual(list(wt.unknowns()), ['inertiatic'])
185
185
 
186
186
    def test_add_control_dir(self):
187
187
        """The control dir and its content should be refused."""
188
188
        self.make_branch_and_tree('.')
189
 
        err = self.run_bzr('add', '.bzr', retcode=3)[1]
 
189
        err = self.run_bzr('add .bzr', retcode=3)[1]
190
190
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
191
 
        err = self.run_bzr('add', '.bzr/README', retcode=3)[1]
 
191
        err = self.run_bzr('add .bzr/README', retcode=3)[1]
192
192
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
193
193
        self.build_tree(['.bzr/crescent'])
194
 
        err = self.run_bzr('add', '.bzr/crescent', retcode=3)[1]
 
194
        err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
195
195
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
 
196
 
 
197
    def test_add_with_wildcards(self):
 
198
        self.requireFeature(NeedsGlobExpansionFeature)
 
199
        self.make_branch_and_tree('.')
 
200
        self.build_tree(['a1', 'a2', 'b', 'c33'])
 
201
        self.run_bzr(['add', 'a?', 'c*'])
 
202
        self.assertEquals(self.run_bzr('unknowns')[0], 'b\n')
 
203
 
 
204
    def test_add_with_wildcards_unicode(self):
 
205
        self.requireFeature(NeedsGlobExpansionFeature)
 
206
        self.make_branch_and_tree('.')
 
207
        self.build_tree([u'\u1234A', u'\u1235A', u'\u1235AA', 'cc'])
 
208
        self.run_bzr(['add', u'\u1234?', u'\u1235*'])
 
209
        self.assertEquals(self.run_bzr('unknowns')[0], 'cc\n')