~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

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
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import ignores
23
 
 
24
22
from bzrlib.tests.blackbox import ExternalBase
25
23
 
26
24
 
28
26
        
29
27
    def test_add_reports(self):
30
28
        """add command prints the names of added files."""
31
 
        ignores._set_user_ignores(['./.bazaar'])
32
 
 
33
29
        self.runbzr('init')
34
30
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
35
31
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
42
38
                           'added dir',
43
39
                           'added dir/sub.txt',
44
40
                           'added top.txt',
45
 
                           'ignored 2 file(s).'],
 
41
                           'ignored 1 file(s).'],
46
42
                          results)
47
43
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
48
44
        results = sorted(out.rstrip('\n').split('\n'))
49
45
        self.assertEquals(['If you wish to add some of these files, please'\
50
46
                           ' add them by name.',
51
 
                           'ignored .bazaar matching "./.bazaar"',
52
47
                           'ignored CVS matching "CVS"'],
53
48
                          results)
54
49
 
66
61
 
67
62
        "bzr add" should add the parent(s) as necessary.
68
63
        """
69
 
        ignores._set_user_ignores(['./.bazaar'])
70
 
 
71
64
        self.runbzr('init')
72
65
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
73
66
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
91
84
 
92
85
        "bzr add" should do this happily.
93
86
        """
94
 
        ignores._set_user_ignores(['./.bazaar'])
95
 
 
96
87
        self.runbzr('init')
97
88
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
98
89
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
105
96
        """Add in subdirectory should add only things from there down"""
106
97
        from bzrlib.workingtree import WorkingTree
107
98
 
108
 
        ignores._set_user_ignores(['./.bazaar'])
109
99
        eq = self.assertEqual
110
100
        ass = self.assertTrue
111
101
        chdir = os.chdir
136
126
        """bzr add foo where foo is missing should error."""
137
127
        self.make_branch_and_tree('.')
138
128
        self.run_bzr('add', 'missing-file', retcode=3)
 
129
 
 
130
    def test_add_from(self):
 
131
        base_tree = self.make_branch_and_tree('base')
 
132
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
 
133
        base_tree.add(['a', 'b', 'b/c'])
 
134
        base_tree.commit('foo')
 
135
 
 
136
        new_tree = self.make_branch_and_tree('new')
 
137
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
 
138
 
 
139
        os.chdir('new')
 
140
        out, err = self.run_bzr('add', '--file-ids-from', '../base')
 
141
        self.assertEqual('', err)
 
142
        self.assertEqualDiff('added a w/ file id from a\n'
 
143
                             'added b w/ file id from b\n'
 
144
                             'added b/c w/ file id from b/c\n',
 
145
                             out)
 
146
 
 
147
        new_tree.read_working_inventory()
 
148
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
 
149
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
 
150
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
 
151
 
 
152
    def test_add_from_subdir(self):
 
153
        base_tree = self.make_branch_and_tree('base')
 
154
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
 
155
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
 
156
        base_tree.commit('foo')
 
157
 
 
158
        new_tree = self.make_branch_and_tree('new')
 
159
        self.build_tree(['new/c', 'new/d'])
 
160
 
 
161
        os.chdir('new')
 
162
        out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
 
163
        self.assertEqual('', err)
 
164
        self.assertEqualDiff('added c w/ file id from b/c\n'
 
165
                             'added d w/ file id from b/d\n',
 
166
                             out)
 
167
 
 
168
        new_tree.read_working_inventory()
 
169
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
 
170
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
 
171
 
 
172
    def test_add_dry_run(self):
 
173
        # ensure that --dry-run actually don't add anything
 
174
        base_tree = self.make_branch_and_tree('.')
 
175
        self.build_tree(['spam'])
 
176
        out = self.run_bzr_captured(['add', '--dry-run'], retcode=0)[0]
 
177
        self.assertEquals('added spam\n', out)
 
178
        out = self.run_bzr_captured(['added'], retcode=0)[0]
 
179
        self.assertEquals('', out)