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 |
|
40 |
def test_10_verbose_commit(self): |
|
41 |
"""Add one file and examine verbose commit output""" |
|
42 |
self.runbzr("init") |
|
43 |
self.build_tree(['hello.txt']) |
|
44 |
self.runbzr("add hello.txt") |
|
45 |
out,err = self.run_bzr("commit", "-m", "added") |
|
46 |
self.assertEqual('', out) |
|
47 |
self.assertEqual('added hello.txt\n' |
|
48 |
'Committed revision 1.\n', |
|
49 |
err) |
|
50 |
||
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
51 |
def prepare_simple_history(self): |
52 |
"""Prepare and return a working tree with one commit of one file""" |
|
53 |
# Commit with modified file should say so
|
|
54 |
wt = BzrDir.create_standalone_workingtree('.') |
|
55 |
self.build_tree(['hello.txt', 'extra.txt']) |
|
56 |
wt.add(['hello.txt']) |
|
57 |
wt.commit(message='added') |
|
58 |
return wt |
|
59 |
||
60 |
def test_verbose_commit_modified(self): |
|
61 |
# Verbose commit of modified file should say so
|
|
62 |
wt = self.prepare_simple_history() |
|
63 |
self.build_tree_contents([('hello.txt', 'new contents')]) |
|
64 |
out, err = self.run_bzr("commit", "-m", "modified") |
|
65 |
self.assertEqual('', out) |
|
66 |
self.assertEqual('modified hello.txt\n' |
|
67 |
'Committed revision 2.\n', |
|
68 |
err) |
|
69 |
||
70 |
def test_verbose_commit_renamed(self): |
|
71 |
# Verbose commit of renamed file should say so
|
|
72 |
wt = self.prepare_simple_history() |
|
73 |
wt.rename_one('hello.txt', 'gutentag.txt') |
|
74 |
out, err = self.run_bzr("commit", "-m", "renamed") |
|
75 |
self.assertEqual('', out) |
|
76 |
self.assertEqual('renamed gutentag.txt\n' |
|
77 |
'Committed revision 2.\n', |
|
78 |
err) |
|
79 |
||
80 |
def test_verbose_commit_moved(self): |
|
81 |
# Verbose commit of file moved to new directory should say so
|
|
82 |
wt = self.prepare_simple_history() |
|
83 |
os.mkdir('subdir') |
|
84 |
wt.add(['subdir']) |
|
85 |
wt.rename_one('hello.txt', 'subdir/hello.txt') |
|
86 |
out, err = self.run_bzr("commit", "-m", "renamed") |
|
87 |
self.assertEqual('', out) |
|
88 |
self.assertEqualDiff('added subdir\n' |
|
89 |
'renamed subdir/hello.txt\n' |
|
90 |
'Committed revision 2.\n', |
|
91 |
err) |
|
92 |
||
93 |
def test_verbose_commit_with_unknown(self): |
|
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
94 |
"""Unknown files should not be listed by default in verbose output""" |
95 |
# Is that really the best policy?
|
|
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
96 |
wt = BzrDir.create_standalone_workingtree('.') |
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
97 |
self.build_tree(['hello.txt', 'extra.txt']) |
1669.2.1
by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files |
98 |
wt.add(['hello.txt']) |
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
99 |
out,err = self.run_bzr("commit", "-m", "added") |
100 |
self.assertEqual('', out) |
|
101 |
self.assertEqual('added hello.txt\n' |
|
102 |
'Committed revision 1.\n', |
|
103 |
err) |
|
104 |
||
1616.1.4
by Martin Pool
Verbose commit shouldn't talk about every unchanged file. |
105 |
def test_16_verbose_commit_with_unchanged(self): |
106 |
"""Unchanged files should not be listed by default in verbose output""" |
|
107 |
self.runbzr("init") |
|
108 |
self.build_tree(['hello.txt', 'unchanged.txt']) |
|
109 |
self.runbzr('add unchanged.txt') |
|
110 |
self.runbzr('commit -m unchanged unchanged.txt') |
|
111 |
self.runbzr("add hello.txt") |
|
112 |
out,err = self.run_bzr("commit", "-m", "added") |
|
113 |
self.assertEqual('', out) |
|
114 |
self.assertEqual('added hello.txt\n' |
|
115 |
'Committed revision 2.\n', |
|
116 |
err) |
|
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
117 |
|
118 |
def test_empty_commit_message(self): |
|
119 |
self.runbzr("init") |
|
120 |
file('foo.c', 'wt').write('int main() {}') |
|
121 |
self.runbzr(['add', 'foo.c']) |
|
1616.1.3
by Martin Pool
Clean up cut&pasted test for verbose commit |
122 |
self.runbzr(["commit", "-m", ""] , retcode=3) |
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
123 |
|
124 |
def test_other_branch_commit(self): |
|
125 |
# this branch is to ensure consistent behaviour, whether we're run
|
|
126 |
# inside a branch, or not.
|
|
127 |
os.mkdir('empty_branch') |
|
128 |
os.chdir('empty_branch') |
|
129 |
self.runbzr('init') |
|
130 |
os.mkdir('branch') |
|
131 |
os.chdir('branch') |
|
132 |
self.runbzr('init') |
|
133 |
file('foo.c', 'wt').write('int main() {}') |
|
134 |
file('bar.c', 'wt').write('int main() {}') |
|
135 |
os.chdir('..') |
|
136 |
self.runbzr(['add', 'branch/foo.c']) |
|
137 |
self.runbzr(['add', 'branch']) |
|
138 |
# can't commit files in different trees; sane error
|
|
139 |
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3) |
|
140 |
self.runbzr('commit -m newstuff branch/foo.c') |
|
141 |
self.runbzr('commit -m newstuff branch') |
|
142 |
self.runbzr('commit -m newstuff branch', retcode=3) |
|
143 |
||
144 |
def test_out_of_date_tree_commit(self): |
|
145 |
# check we get an error code and a clear message committing with an out
|
|
146 |
# of date checkout
|
|
147 |
self.make_branch_and_tree('branch') |
|
148 |
# make a checkout
|
|
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
149 |
self.runbzr('checkout --lightweight branch checkout') |
1508.1.22
by Robert Collins
implement out of date working tree checks in commit. |
150 |
# commit to the original branch to make the checkout out of date
|
151 |
self.runbzr('commit --unchanged -m message branch') |
|
152 |
# now commit to the checkout should emit
|
|
153 |
# ERROR: Out of date with the branch, 'bzr update' is suggested
|
|
154 |
output = self.runbzr('commit --unchanged -m checkout_message ' |
|
155 |
'checkout', retcode=3) |
|
156 |
self.assertEqual(output, |
|
157 |
('', |
|
158 |
"bzr: ERROR: Working tree is out of date, please run "
|
|
159 |
"'bzr update'.\n")) |
|
1587.1.8
by Robert Collins
Local commits on unbound branches fail. |
160 |
|
161 |
def test_local_commit_unbound(self): |
|
162 |
# a --local commit on an unbound branch is an error
|
|
163 |
self.make_branch_and_tree('.') |
|
164 |
out, err = self.run_bzr('commit', '--local', retcode=3) |
|
165 |
self.assertEqualDiff('', out) |
|
166 |
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits ' |
|
167 |
'on unbound branches.\n', err) |