/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Michael Ellerman
  • Date: 2006-05-31 08:44:29 UTC
  • mto: (1711.2.63 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1792.
  • Revision ID: michael@ellerman.id.au-20060531084429-35e5429abda9f560
Add optional location to ancestry and fix behaviour for checkouts.

This adds an optional location parameter to the ancestry command. It also
changes the behaviour of ancestry on checkouts such that if they have
been created with a subset of the branch history, only the subset is
shown by 'bzr ancestry'. Tests for all of that as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
 
from cStringIO import StringIO
21
20
import os
22
21
import re
23
 
import shutil
24
22
import sys
25
23
 
26
24
from bzrlib.branch import Branch
27
 
import bzrlib.bzrdir as bzrdir
 
25
from bzrlib.bzrdir import BzrDir
28
26
from bzrlib.errors import BzrCommandError
29
27
from bzrlib.tests.blackbox import ExternalBase
30
28
from bzrlib.workingtree import WorkingTree
39
37
        self.build_tree(['hello.txt'])
40
38
        self.runbzr("commit -m empty", retcode=3)
41
39
 
 
40
    def test_commit_with_path(self):
 
41
        """Commit tree with path of root specified"""
 
42
        self.run_bzr('init', 'a')
 
43
        self.build_tree(['a/a_file'])
 
44
        self.run_bzr('add', 'a/a_file')
 
45
        self.run_bzr('commit', '-m', 'first commit', 'a')
 
46
 
 
47
        self.run_bzr('branch', 'a', 'b')
 
48
        self.build_tree_contents([('b/a_file', 'changes in b')])
 
49
        self.run_bzr('commit', '-m', 'first commit in b', 'b')
 
50
 
 
51
        self.build_tree_contents([('a/a_file', 'new contents')])
 
52
        self.run_bzr('commit', '-m', 'change in a', 'a')
 
53
 
 
54
        os.chdir('b')
 
55
        self.run_bzr('merge', '../a', retcode=1) # will conflict
 
56
        os.chdir('..')
 
57
        self.run_bzr('resolved', 'b/a_file')
 
58
        self.run_bzr('commit', '-m', 'merge into b', 'b')
 
59
 
 
60
 
42
61
    def test_10_verbose_commit(self):
43
62
        """Add one file and examine verbose commit output"""
44
63
        self.runbzr("init")
50
69
                         'Committed revision 1.\n',
51
70
                         err)
52
71
 
53
 
    def test_15_verbose_commit_with_unknown(self):
 
72
    def prepare_simple_history(self):
 
73
        """Prepare and return a working tree with one commit of one file"""
 
74
        # Commit with modified file should say so
 
75
        wt = BzrDir.create_standalone_workingtree('.')
 
76
        self.build_tree(['hello.txt', 'extra.txt'])
 
77
        wt.add(['hello.txt'])
 
78
        wt.commit(message='added')
 
79
        return wt
 
80
 
 
81
    def test_verbose_commit_modified(self):
 
82
        # Verbose commit of modified file should say so
 
83
        wt = self.prepare_simple_history()
 
84
        self.build_tree_contents([('hello.txt', 'new contents')])
 
85
        out, err = self.run_bzr("commit", "-m", "modified")
 
86
        self.assertEqual('', out)
 
87
        self.assertEqual('modified hello.txt\n'
 
88
                         'Committed revision 2.\n',
 
89
                         err)
 
90
 
 
91
    def test_verbose_commit_renamed(self):
 
92
        # Verbose commit of renamed file should say so
 
93
        wt = self.prepare_simple_history()
 
94
        wt.rename_one('hello.txt', 'gutentag.txt')
 
95
        out, err = self.run_bzr("commit", "-m", "renamed")
 
96
        self.assertEqual('', out)
 
97
        self.assertEqual('renamed hello.txt => gutentag.txt\n'
 
98
                         'Committed revision 2.\n',
 
99
                         err)
 
100
 
 
101
    def test_verbose_commit_moved(self):
 
102
        # Verbose commit of file moved to new directory should say so
 
103
        wt = self.prepare_simple_history()
 
104
        os.mkdir('subdir')
 
105
        wt.add(['subdir'])
 
106
        wt.rename_one('hello.txt', 'subdir/hello.txt')
 
107
        out, err = self.run_bzr("commit", "-m", "renamed")
 
108
        self.assertEqual('', out)
 
109
        self.assertEqualDiff('added subdir\n'
 
110
                             'renamed hello.txt => subdir/hello.txt\n'
 
111
                             'Committed revision 2.\n',
 
112
                             err)
 
113
 
 
114
    def test_verbose_commit_with_unknown(self):
54
115
        """Unknown files should not be listed by default in verbose output"""
55
116
        # Is that really the best policy?
56
 
        self.runbzr("init")
 
117
        wt = BzrDir.create_standalone_workingtree('.')
57
118
        self.build_tree(['hello.txt', 'extra.txt'])
58
 
        self.runbzr("add hello.txt")
 
119
        wt.add(['hello.txt'])
59
120
        out,err = self.run_bzr("commit", "-m", "added")
60
121
        self.assertEqual('', out)
61
122
        self.assertEqual('added hello.txt\n'
62
123
                         'Committed revision 1.\n',
63
124
                         err)
64
125
 
65
 
    def test_16_verbose_commit_with_unchanged(self):
 
126
    def test_verbose_commit_with_unchanged(self):
66
127
        """Unchanged files should not be listed by default in verbose output"""
67
128
        self.runbzr("init")
68
129
        self.build_tree(['hello.txt', 'unchanged.txt'])
75
136
                         'Committed revision 2.\n',
76
137
                         err)
77
138
 
 
139
    def test_commit_merge_reports_all_modified_files(self):
 
140
        # the commit command should show all the files that are shown by
 
141
        # bzr diff or bzr status when committing, even when they were not
 
142
        # changed by the user but rather through doing a merge.
 
143
        this_tree = self.make_branch_and_tree('this')
 
144
        # we need a bunch of files and dirs, to perform one action on each.
 
145
        self.build_tree([
 
146
            'this/dirtorename/',
 
147
            'this/dirtoreparent/',
 
148
            'this/dirtoleave/',
 
149
            'this/dirtoremove/',
 
150
            'this/filetoreparent',
 
151
            'this/filetorename',
 
152
            'this/filetomodify',
 
153
            'this/filetoremove',
 
154
            'this/filetoleave']
 
155
            )
 
156
        this_tree.add([
 
157
            'dirtorename',
 
158
            'dirtoreparent',
 
159
            'dirtoleave',
 
160
            'dirtoremove',
 
161
            'filetoreparent',
 
162
            'filetorename',
 
163
            'filetomodify',
 
164
            'filetoremove',
 
165
            'filetoleave']
 
166
            )
 
167
        this_tree.commit('create_files')
 
168
        other_dir = this_tree.bzrdir.sprout('other')
 
169
        other_tree = other_dir.open_workingtree()
 
170
        other_tree.lock_write()
 
171
        # perform the needed actions on the files and dirs.
 
172
        try:
 
173
            other_tree.rename_one('dirtorename', 'renameddir')
 
174
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
 
175
            other_tree.rename_one('filetorename', 'renamedfile')
 
176
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
177
            other_tree.remove(['dirtoremove', 'filetoremove'])
 
178
            self.build_tree_contents([
 
179
                ('other/newdir/', ),
 
180
                ('other/filetomodify', 'new content'),
 
181
                ('other/newfile', 'new file content')])
 
182
            other_tree.add('newfile')
 
183
            other_tree.add('newdir/')
 
184
            other_tree.commit('modify all sample files and dirs.')
 
185
        finally:
 
186
            other_tree.unlock()
 
187
        self.merge(other_tree.branch, this_tree)
 
188
        os.chdir('this')
 
189
        out,err = self.run_bzr("commit", "-m", "added")
 
190
        os.chdir('..')
 
191
        self.assertEqual('', out)
 
192
        self.assertEqualDiff(
 
193
            'modified filetomodify\n'
 
194
            'added newdir\n'
 
195
            'added newfile\n'
 
196
            'renamed dirtorename => renameddir\n'
 
197
            'renamed dirtoreparent => renameddir/reparenteddir\n'
 
198
            'renamed filetoreparent => renameddir/reparentedfile\n'
 
199
            'renamed filetorename => renamedfile\n'
 
200
            'deleted dirtoremove\n'
 
201
            'deleted filetoremove\n'
 
202
            'Committed revision 2.\n',
 
203
            err)
 
204
 
78
205
    def test_empty_commit_message(self):
79
206
        self.runbzr("init")
80
207
        file('foo.c', 'wt').write('int main() {}')
125
252
        self.assertEqualDiff('', out)
126
253
        self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
127
254
                             'on unbound branches.\n', err)
 
255
 
 
256
    def test_commit_a_text_merge_in_a_checkout(self):
 
257
        # checkouts perform multiple actions in a transaction across bond
 
258
        # branches and their master, and have been observed to fail in the
 
259
        # past. This is a user story reported to fail in bug #43959 where 
 
260
        # a merge done in a checkout (using the update command) failed to
 
261
        # commit correctly.
 
262
        self.run_bzr('init', 'trunk')
 
263
 
 
264
        self.run_bzr('checkout', 'trunk', 'u1')
 
265
        self.build_tree_contents([('u1/hosts', 'initial contents')])
 
266
        self.run_bzr('add', 'u1/hosts')
 
267
        self.run_bzr('commit', '-m', 'add hosts', 'u1')
 
268
 
 
269
        self.run_bzr('checkout', 'trunk', 'u2')
 
270
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
 
271
        self.run_bzr('commit', '-m', 'checkin from u2', 'u2')
 
272
 
 
273
        # make an offline commits
 
274
        self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
 
275
        self.run_bzr('commit', '-m', 'checkin offline', '--local', 'u1')
 
276
 
 
277
        # now try to pull in online work from u2, and then commit our offline
 
278
        # work as a merge
 
279
        # retcode 1 as we expect a text conflict
 
280
        self.run_bzr('update', 'u1', retcode=1)
 
281
        self.run_bzr('resolved', 'u1/hosts')
 
282
        # add a text change here to represent resolving the merge conflicts in
 
283
        # favour of a new version of the file not identical to either the u1
 
284
        # version or the u2 version.
 
285
        self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
 
286
        self.run_bzr('commit', '-m', 'checkin merge of the offline work from u1', 'u1')