bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2006 Canonical Ltd
|
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
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 |
"""Tests for repository commit builder."""
|
|
18 |
||
|
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
19 |
from bzrlib import inventory |
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
20 |
from bzrlib.errors import NonAsciiRevisionId, CannotSetRevisionId |
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
21 |
from bzrlib.repository import CommitBuilder |
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
22 |
from bzrlib import tests |
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
23 |
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository |
24 |
||
25 |
||
26 |
class TestCommitBuilder(TestCaseWithRepository): |
|
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
27 |
|
|
1740.3.10
by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m. |
28 |
def test_get_commit_builder(self): |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
29 |
branch = self.make_branch('.') |
30 |
branch.repository.lock_write() |
|
31 |
builder = branch.repository.get_commit_builder( |
|
32 |
branch, [], branch.get_config()) |
|
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
33 |
self.assertIsInstance(builder, CommitBuilder) |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
34 |
branch.repository.commit_write_group() |
35 |
branch.repository.unlock() |
|
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
36 |
|
|
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
37 |
def record_root(self, builder, tree): |
38 |
if builder.record_root_entry is True: |
|
|
2255.7.8
by John Arbash Meinel
Lock the tree when using a commit builder. |
39 |
tree.lock_read() |
40 |
try: |
|
41 |
ie = tree.inventory.root |
|
42 |
finally: |
|
43 |
tree.unlock() |
|
|
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
44 |
parent_tree = tree.branch.repository.revision_tree(None) |
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
45 |
parent_invs = [] |
|
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
46 |
builder.record_entry_contents(ie, parent_invs, '', tree) |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
47 |
|
|
1740.3.10
by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m. |
48 |
def test_finish_inventory(self): |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
49 |
tree = self.make_branch_and_tree(".") |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
50 |
tree.lock_write() |
|
2617.6.8
by Robert Collins
Review feedback and documentation. |
51 |
try: |
52 |
builder = tree.branch.get_commit_builder([]) |
|
53 |
self.record_root(builder, tree) |
|
54 |
builder.finish_inventory() |
|
55 |
tree.branch.repository.commit_write_group() |
|
56 |
finally: |
|
57 |
tree.unlock() |
|
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
58 |
|
|
1740.3.10
by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m. |
59 |
def test_commit_message(self): |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
60 |
tree = self.make_branch_and_tree(".") |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
61 |
tree.lock_write() |
|
2617.6.8
by Robert Collins
Review feedback and documentation. |
62 |
try: |
63 |
builder = tree.branch.get_commit_builder([]) |
|
64 |
self.record_root(builder, tree) |
|
65 |
builder.finish_inventory() |
|
66 |
rev_id = builder.commit('foo bar blah') |
|
67 |
finally: |
|
68 |
tree.unlock() |
|
|
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
69 |
rev = tree.branch.repository.get_revision(rev_id) |
70 |
self.assertEqual('foo bar blah', rev.message) |
|
71 |
||
|
1740.3.10
by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m. |
72 |
def test_commit_with_revision_id(self): |
|
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
73 |
tree = self.make_branch_and_tree(".") |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
74 |
tree.lock_write() |
|
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
75 |
try: |
|
2617.6.8
by Robert Collins
Review feedback and documentation. |
76 |
# use a unicode revision id to test more corner cases.
|
77 |
# The repository layer is meant to handle this.
|
|
78 |
revision_id = u'\xc8abc'.encode('utf8') |
|
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
79 |
try: |
|
2617.6.8
by Robert Collins
Review feedback and documentation. |
80 |
try: |
81 |
builder = tree.branch.get_commit_builder([], |
|
82 |
revision_id=revision_id) |
|
83 |
except NonAsciiRevisionId: |
|
84 |
revision_id = 'abc' |
|
85 |
builder = tree.branch.get_commit_builder([], |
|
86 |
revision_id=revision_id) |
|
87 |
except CannotSetRevisionId: |
|
88 |
# This format doesn't support supplied revision ids
|
|
89 |
return
|
|
90 |
self.record_root(builder, tree) |
|
91 |
builder.finish_inventory() |
|
92 |
self.assertEqual(revision_id, builder.commit('foo bar')) |
|
93 |
finally: |
|
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
94 |
tree.unlock() |
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
95 |
self.assertTrue(tree.branch.repository.has_revision(revision_id)) |
96 |
# the revision id must be set on the inventory when saving it. This
|
|
97 |
# does not precisely test that - a repository that wants to can add it
|
|
98 |
# on deserialisation, but thats all the current contract guarantees
|
|
99 |
# anyway.
|
|
100 |
self.assertEqual(revision_id, |
|
101 |
tree.branch.repository.get_inventory(revision_id).revision_id) |
|
|
1740.3.8
by Jelmer Vernooij
Move make_revision() to commit builder. |
102 |
|
|
1910.2.8
by Aaron Bentley
Fix commit_builder when root not passed to record_entry_contents |
103 |
def test_commit_without_root(self): |
104 |
"""This should cause a deprecation warning, not an assertion failure""" |
|
105 |
tree = self.make_branch_and_tree(".") |
|
|
2255.7.8
by John Arbash Meinel
Lock the tree when using a commit builder. |
106 |
tree.lock_write() |
107 |
try: |
|
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
108 |
if tree.branch.repository.supports_rich_root(): |
109 |
raise tests.TestSkipped('Format requires root') |
|
110 |
self.build_tree(['foo']) |
|
111 |
tree.add('foo', 'foo-id') |
|
|
2255.7.8
by John Arbash Meinel
Lock the tree when using a commit builder. |
112 |
entry = tree.inventory['foo-id'] |
113 |
builder = tree.branch.get_commit_builder([]) |
|
114 |
self.callDeprecated(['Root entry should be supplied to' |
|
115 |
' record_entry_contents, as of bzr 0.10.'], |
|
116 |
builder.record_entry_contents, entry, [], 'foo', tree) |
|
117 |
builder.finish_inventory() |
|
118 |
rev_id = builder.commit('foo bar') |
|
119 |
finally: |
|
120 |
tree.unlock() |
|
|
1910.2.8
by Aaron Bentley
Fix commit_builder when root not passed to record_entry_contents |
121 |
|
|
1740.3.10
by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m. |
122 |
def test_commit(self): |
|
1740.3.8
by Jelmer Vernooij
Move make_revision() to commit builder. |
123 |
tree = self.make_branch_and_tree(".") |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
124 |
tree.lock_write() |
|
2617.6.8
by Robert Collins
Review feedback and documentation. |
125 |
try: |
126 |
builder = tree.branch.get_commit_builder([]) |
|
127 |
self.record_root(builder, tree) |
|
128 |
builder.finish_inventory() |
|
129 |
rev_id = builder.commit('foo bar') |
|
130 |
finally: |
|
131 |
tree.unlock() |
|
|
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
132 |
self.assertNotEqual(None, rev_id) |
133 |
self.assertTrue(tree.branch.repository.has_revision(rev_id)) |
|
|
1757.1.2
by Robert Collins
Bugfix CommitBuilders recording of the inventory revision id. |
134 |
# the revision id must be set on the inventory when saving it. This does not
|
135 |
# precisely test that - a repository that wants to can add it on deserialisation,
|
|
136 |
# but thats all the current contract guarantees anyway.
|
|
137 |
self.assertEqual(rev_id, tree.branch.repository.get_inventory(rev_id).revision_id) |
|
|
2041.1.1
by John Arbash Meinel
Add a 'get_tree()' call that returns a RevisionTree for the newly committed tree |
138 |
|
|
2041.1.5
by John Arbash Meinel
CommitBuilder.get_tree => CommitBuilder.revision_tree |
139 |
def test_revision_tree(self): |
|
2041.1.1
by John Arbash Meinel
Add a 'get_tree()' call that returns a RevisionTree for the newly committed tree |
140 |
tree = self.make_branch_and_tree(".") |
|
2617.6.2
by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit. |
141 |
tree.lock_write() |
|
2617.6.8
by Robert Collins
Review feedback and documentation. |
142 |
try: |
143 |
builder = tree.branch.get_commit_builder([]) |
|
144 |
self.record_root(builder, tree) |
|
145 |
builder.finish_inventory() |
|
146 |
rev_id = builder.commit('foo bar') |
|
147 |
finally: |
|
148 |
tree.unlock() |
|
|
2041.1.5
by John Arbash Meinel
CommitBuilder.get_tree => CommitBuilder.revision_tree |
149 |
rev_tree = builder.revision_tree() |
|
2041.1.1
by John Arbash Meinel
Add a 'get_tree()' call that returns a RevisionTree for the newly committed tree |
150 |
# Just a couple simple tests to ensure that it actually follows
|
151 |
# the RevisionTree api.
|
|
152 |
self.assertEqual(rev_id, rev_tree.get_revision_id()) |
|
153 |
self.assertEqual([], rev_tree.get_parent_ids()) |
|
|
2255.7.65
by Robert Collins
Split test_root_revision_entry into tree and repository portions. |
154 |
|
155 |
def test_root_entry_has_revision(self): |
|
156 |
# test the root revision created and put in the basis
|
|
157 |
# has the right rev id.
|
|
158 |
tree = self.make_branch_and_tree('.') |
|
159 |
rev_id = tree.commit('message') |
|
160 |
basis_tree = tree.basis_tree() |
|
161 |
basis_tree.lock_read() |
|
162 |
self.addCleanup(basis_tree.unlock) |
|
163 |
self.assertEqual(rev_id, basis_tree.inventory.root.revision) |
|
164 |