bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
1 |
# Copyright (C) 2005, 2006 by Canonical Ltd
|
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
18 |
"""Tests for the commit CLI of bzr."""
|
|
19 |
||
20 |
import os |
|
21 |
import re |
|
22 |
import sys |
|
23 |
||
24 |
from bzrlib.branch import Branch |
|
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
25 |
from bzrlib.bzrdir import BzrDir |
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
26 |
from bzrlib.errors import BzrCommandError |
27 |
from bzrlib.tests.blackbox import ExternalBase |
|
28 |
from bzrlib.workingtree import WorkingTree |
|
29 |
||
30 |
||
31 |
class TestCommit(ExternalBase): |
|
32 |
||
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
33 |
def test_05_empty_commit(self): |
34 |
"""Commit of tree with no versioned files should fail""" |
|
35 |
# If forced, it should succeed, but this is not tested here.
|
|
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
36 |
self.runbzr("init") |
37 |
self.build_tree(['hello.txt']) |
|
38 |
self.runbzr("commit -m empty", retcode=3) |
|
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
39 |
|
1704.2.11
by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges. |
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 |
||
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
61 |
def test_10_verbose_commit(self): |
62 |
"""Add one file and examine verbose commit output""" |
|
63 |
self.runbzr("init") |
|
64 |
self.build_tree(['hello.txt']) |
|
65 |
self.runbzr("add hello.txt") |
|
66 |
out,err = self.run_bzr("commit", "-m", "added") |
|
67 |
self.assertEqual('', out) |
|
68 |
self.assertEqual('added hello.txt\n' |
|
69 |
'Committed revision 1.\n', |
|
70 |
err) |
|
71 |
||
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
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 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 subdir/hello.txt\n' |
|
111 |
'Committed revision 2.\n', |
|
112 |
err) |
|
113 |
||
114 |
def test_verbose_commit_with_unknown(self): |
|
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
115 |
"""Unknown files should not be listed by default in verbose output""" |
116 |
# Is that really the best policy?
|
|
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
117 |
wt = BzrDir.create_standalone_workingtree('.') |
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
118 |
self.build_tree(['hello.txt', 'extra.txt']) |
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
119 |
wt.add(['hello.txt']) |
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
120 |
out,err = self.run_bzr("commit", "-m", "added") |
121 |
self.assertEqual('', out) |
|
122 |
self.assertEqual('added hello.txt\n' |
|
123 |
'Committed revision 1.\n', |
|
124 |
err) |
|
125 |
||
1616.1.4
by Martin Pool
Verbose commit shouldn't talk about every unchanged file. |
126 |
def test_16_verbose_commit_with_unchanged(self): |
127 |
"""Unchanged files should not be listed by default in verbose output""" |
|
128 |
self.runbzr("init") |
|
129 |
self.build_tree(['hello.txt', 'unchanged.txt']) |
|
130 |
self.runbzr('add unchanged.txt') |
|
131 |
self.runbzr('commit -m unchanged unchanged.txt') |
|
132 |
self.runbzr("add hello.txt") |
|
133 |
out,err = self.run_bzr("commit", "-m", "added") |
|
134 |
self.assertEqual('', out) |
|
135 |
self.assertEqual('added hello.txt\n' |
|
136 |
'Committed revision 2.\n', |
|
137 |
err) |
|
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
138 |
|
139 |
def test_empty_commit_message(self): |
|
140 |
self.runbzr("init") |
|
141 |
file('foo.c', 'wt').write('int main() {}') |
|
142 |
self.runbzr(['add', 'foo.c']) |
|
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
143 |
self.runbzr(["commit", "-m", ""] , retcode=3) |
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
144 |
|
145 |
def test_other_branch_commit(self): |
|
146 |
# this branch is to ensure consistent behaviour, whether we're run
|
|
147 |
# inside a branch, or not.
|
|
148 |
os.mkdir('empty_branch') |
|
149 |
os.chdir('empty_branch') |
|
150 |
self.runbzr('init') |
|
151 |
os.mkdir('branch') |
|
152 |
os.chdir('branch') |
|
153 |
self.runbzr('init') |
|
154 |
file('foo.c', 'wt').write('int main() {}') |
|
155 |
file('bar.c', 'wt').write('int main() {}') |
|
156 |
os.chdir('..') |
|
157 |
self.runbzr(['add', 'branch/foo.c']) |
|
158 |
self.runbzr(['add', 'branch']) |
|
159 |
# can't commit files in different trees; sane error
|
|
160 |
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3) |
|
161 |
self.runbzr('commit -m newstuff branch/foo.c') |
|
162 |
self.runbzr('commit -m newstuff branch') |
|
163 |
self.runbzr('commit -m newstuff branch', retcode=3) |
|
164 |
||
165 |
def test_out_of_date_tree_commit(self): |
|
166 |
# check we get an error code and a clear message committing with an out
|
|
167 |
# of date checkout
|
|
168 |
self.make_branch_and_tree('branch') |
|
169 |
# make a checkout
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
170 |
self.runbzr('checkout --lightweight branch checkout') |
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
171 |
# commit to the original branch to make the checkout out of date
|
172 |
self.runbzr('commit --unchanged -m message branch') |
|
173 |
# now commit to the checkout should emit
|
|
174 |
# ERROR: Out of date with the branch, 'bzr update' is suggested
|
|
175 |
output = self.runbzr('commit --unchanged -m checkout_message ' |
|
176 |
'checkout', retcode=3) |
|
177 |
self.assertEqual(output, |
|
178 |
('', |
|
179 |
"bzr: ERROR: Working tree is out of date, please run "
|
|
180 |
"'bzr update'.\n")) |
|
1587.1.8
by Robert Collins
Local commits on unbound branches fail. |
181 |
|
182 |
def test_local_commit_unbound(self): |
|
183 |
# a --local commit on an unbound branch is an error
|
|
184 |
self.make_branch_and_tree('.') |
|
185 |
out, err = self.run_bzr('commit', '--local', retcode=3) |
|
186 |
self.assertEqualDiff('', out) |
|
187 |
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits ' |
|
188 |
'on unbound branches.\n', err) |
|
1704.2.12
by Martin Pool
use the correct transaction when committing snapshot (Malone: #43959) |
189 |
|
190 |
def test_commit_a_text_merge_in_a_checkout(self): |
|
191 |
# checkouts perform multiple actions in a transaction across bond
|
|
192 |
# branches and their master, and have been observed to fail in the
|
|
193 |
# past. This is a user story reported to fail in bug #43959 where
|
|
194 |
# a merge done in a checkout (using the update command) failed to
|
|
195 |
# commit correctly.
|
|
196 |
self.run_bzr('init', 'trunk') |
|
197 |
||
198 |
self.run_bzr('checkout', 'trunk', 'u1') |
|
199 |
self.build_tree_contents([('u1/hosts', 'initial contents')]) |
|
200 |
self.run_bzr('add', 'u1/hosts') |
|
201 |
self.run_bzr('commit', '-m', 'add hosts', 'u1') |
|
202 |
||
203 |
self.run_bzr('checkout', 'trunk', 'u2') |
|
204 |
self.build_tree_contents([('u2/hosts', 'altered in u2')]) |
|
205 |
self.run_bzr('commit', '-m', 'checkin from u2', 'u2') |
|
206 |
||
207 |
# make an offline commits
|
|
208 |
self.build_tree_contents([('u1/hosts', 'first offline change in u1')]) |
|
209 |
self.run_bzr('commit', '-m', 'checkin offline', '--local', 'u1') |
|
210 |
||
211 |
# now try to pull in online work from u2, and then commit our offline
|
|
212 |
# work as a merge
|
|
213 |
# retcode 1 as we expect a text conflict
|
|
214 |
self.run_bzr('update', 'u1', retcode=1) |
|
215 |
self.run_bzr('resolved', 'u1/hosts') |
|
216 |
# add a text change here to represent resolving the merge conflicts in
|
|
217 |
# favour of a new version of the file not identical to either the u1
|
|
218 |
# version or the u2 version.
|
|
219 |
self.build_tree_contents([('u1/hosts', 'merge resolution\n')]) |
|
220 |
self.run_bzr('commit', '-m', 'checkin merge of the offline work from u1', 'u1') |