~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-03-08 04:06:06 UTC
  • mfrom: (2323.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070308040606-84gsniv56huiyjt4
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
28
28
        """add command prints the names of added files."""
29
29
        self.runbzr('init')
30
30
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
 
31
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
31
32
        out = self.run_bzr_captured(['add'], retcode=0)[0]
32
33
        # the ordering is not defined at the moment
33
34
        results = sorted(out.rstrip('\n').split('\n'))
34
35
        self.assertEquals(['If you wish to add some of these files, please'\
35
36
                           ' add them by name.',
 
37
                           'added .bzrignore',
36
38
                           'added dir',
37
39
                           'added dir/sub.txt',
38
40
                           'added top.txt',
93
95
    def test_subdir_add(self):
94
96
        """Add in subdirectory should add only things from there down"""
95
97
        from bzrlib.workingtree import WorkingTree
96
 
        
 
98
 
97
99
        eq = self.assertEqual
98
 
        ass = self.assert_
 
100
        ass = self.assertTrue
99
101
        chdir = os.chdir
100
102
        
101
103
        t = self.make_branch_and_tree('.')
109
111
        
110
112
        self.build_tree(['src/foo.c'])
111
113
        
 
114
        # add with no arguments in a subdirectory gets only files below that
 
115
        # subdirectory
112
116
        chdir('src')
113
117
        self.run_bzr('add')
114
 
        
115
118
        self.assertEquals(self.capture('unknowns'), 'README\n')
116
 
        eq(len(t.read_working_inventory()), 3)
 
119
        # reopen to see the new changes
 
120
        t = t.bzrdir.open_workingtree()
 
121
        versioned = [path for path, entry in t.iter_entries_by_dir()]
 
122
        self.assertEquals(versioned,
 
123
            ['', 'src', 'src/foo.c'])
117
124
                
 
125
        # add from the parent directory should pick up all file names
118
126
        chdir('..')
119
127
        self.run_bzr('add')
120
128
        self.assertEquals(self.capture('unknowns'), '')
121
129
        self.run_bzr('check')
 
130
 
 
131
    def test_add_missing(self):
 
132
        """bzr add foo where foo is missing should error."""
 
133
        self.make_branch_and_tree('.')
 
134
        self.run_bzr('add', 'missing-file', retcode=3)
 
135
 
 
136
    def test_add_from(self):
 
137
        base_tree = self.make_branch_and_tree('base')
 
138
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
 
139
        base_tree.add(['a', 'b', 'b/c'])
 
140
        base_tree.commit('foo')
 
141
 
 
142
        new_tree = self.make_branch_and_tree('new')
 
143
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
 
144
 
 
145
        os.chdir('new')
 
146
        out, err = self.run_bzr('add', '--file-ids-from', '../base')
 
147
        self.assertEqual('', err)
 
148
        self.assertEqualDiff('added a w/ file id from a\n'
 
149
                             'added b w/ file id from b\n'
 
150
                             'added b/c w/ file id from b/c\n',
 
151
                             out)
 
152
        new_tree = new_tree.bzrdir.open_workingtree()
 
153
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
 
154
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
 
155
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
 
156
 
 
157
    def test_add_from_subdir(self):
 
158
        base_tree = self.make_branch_and_tree('base')
 
159
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
 
160
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
 
161
        base_tree.commit('foo')
 
162
 
 
163
        new_tree = self.make_branch_and_tree('new')
 
164
        self.build_tree(['new/c', 'new/d'])
 
165
 
 
166
        os.chdir('new')
 
167
        out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
 
168
        self.assertEqual('', err)
 
169
        self.assertEqualDiff('added c w/ file id from b/c\n'
 
170
                             'added d w/ file id from b/d\n',
 
171
                             out)
 
172
 
 
173
        new_tree = new_tree.bzrdir.open_workingtree()
 
174
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
 
175
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
 
176
 
 
177
    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)
 
185
 
 
186
    def test_add_control_dir(self):
 
187
        """The control dir and its content should be refused."""
 
188
        self.make_branch_and_tree('.')
 
189
        err = self.run_bzr('add', '.bzr', retcode=3)[1]
 
190
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
 
191
        err = self.run_bzr('add', '.bzr/README', retcode=3)[1]
 
192
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
 
193
        self.build_tree(['.bzr/crescent'])
 
194
        err = self.run_bzr('add', '.bzr/crescent', retcode=3)[1]
 
195
        self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')