/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
1
# Copyright (C) 2007 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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
16
17
"""Test our ability to build up test repositories"""
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
from __future__ import absolute_import
20
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
21
from cStringIO import StringIO
22
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
23
from dulwich.repo import Repo as GitRepo
24
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from .. import tests
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
26
27
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
28
class TestGitBranchBuilder(tests.TestCase):
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
29
30
    def test__create_blob(self):
31
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
32
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
33
        self.assertEqual(1, builder._create_blob('foo\nbar\n'))
34
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
35
                             stream.getvalue())
36
37
    def test_set_file(self):
38
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
39
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
40
        builder.set_file('foobar', 'foo\nbar\n', False)
41
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
42
                             stream.getvalue())
43
        self.assertEqual(['M 100644 :1 foobar\n'], builder.commit_info)
44
45
    def test_set_file_unicode(self):
46
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
47
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
48
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
49
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
50
                             stream.getvalue())
51
        self.assertEqual(['M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info)
52
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
53
    def test_set_file_newline(self):
54
        stream = StringIO()
55
        builder = tests.GitBranchBuilder(stream)
56
        builder.set_file(u'foo\nbar', 'contents\nbar\n', False)
57
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
58
                             stream.getvalue())
59
        self.assertEqual(['M 100644 :1 "foo\\nbar"\n'], builder.commit_info)
60
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
61
    def test_set_file_executable(self):
62
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
63
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
64
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', True)
65
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
66
                             stream.getvalue())
67
        self.assertEqual(['M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info)
68
69
    def test_set_link(self):
70
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
71
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
72
        builder.set_link(u'f\xb5/bar', 'link/contents')
73
        self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
74
                             stream.getvalue())
75
        self.assertEqual(['M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info)
76
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
77
    def test_set_link_newline(self):
78
        stream = StringIO()
79
        builder = tests.GitBranchBuilder(stream)
80
        builder.set_link(u'foo\nbar', 'link/contents')
81
        self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
82
                             stream.getvalue())
83
        self.assertEqual(['M 120000 :1 "foo\\nbar"\n'], builder.commit_info)
84
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
85
    def test_delete_entry(self):
86
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
87
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
88
        builder.delete_entry(u'path/to/f\xb5')
89
        self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info)
90
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
91
    def test_delete_entry_newline(self):
92
        stream = StringIO()
93
        builder = tests.GitBranchBuilder(stream)
94
        builder.delete_entry(u'path/to/foo\nbar')
95
        self.assertEqual(['D "path/to/foo\\nbar"\n'], builder.commit_info)
96
97
    def test_encode_path(self):
98
        encode = tests.GitBranchBuilder._encode_path
99
        # Unicode is encoded to utf-8
100
        self.assertEqual(encode(u'f\xb5'), 'f\xc2\xb5')
101
        # The name must be quoted if it starts by a double quote or contains a
102
        # newline.
103
        self.assertEqual(encode(u'"foo'), '"\\"foo"')
104
        self.assertEqual(encode(u'fo\no'), '"fo\\no"')
105
        # When the name is quoted, all backslash and quote chars must be
106
        # escaped.
107
        self.assertEqual(encode(u'fo\\o\nbar'), '"fo\\\\o\\nbar"')
108
        self.assertEqual(encode(u'fo"o"\nbar'), '"fo\\"o\\"\\nbar"')
109
        # Other control chars, such as \r, need not be escaped.
110
        self.assertEqual(encode(u'foo\r\nbar'), '"foo\r\\nbar"')
111
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
112
    def test_add_and_commit(self):
113
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
114
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
115
116
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
117
        self.assertEqual('2', builder.commit('Joe Foo <joe@foo.com>',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
118
                                           u'committing f\xb5/bar',
119
                                           timestamp=1194586400,
120
                                           timezone='+0100'))
121
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
122
                             'commit refs/heads/master\n'
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
123
                             'mark :2\n'
124
                             'committer Joe Foo <joe@foo.com> 1194586400 +0100\n'
125
                             'data 18\n'
126
                             'committing f\xc2\xb5/bar'
127
                             '\n'
128
                             'M 100644 :1 f\xc2\xb5/bar\n'
129
                             '\n',
130
                             stream.getvalue())
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
131
132
    def test_commit_base(self):
133
        stream = StringIO()
134
        builder = tests.GitBranchBuilder(stream)
135
136
        builder.set_file(u'foo', 'contents\nfoo\n', False)
137
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
138
                            timestamp=1194586400)
139
        r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
140
                            timestamp=1194586405)
141
        r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
142
                            timestamp=1194586410,
143
                            base=r1)
144
145
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
146
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
147
                             'mark :2\n'
148
                             'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
149
                             'data 5\n'
150
                             'first'
151
                             '\n'
152
                             'M 100644 :1 foo\n'
153
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
154
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
155
                             'mark :3\n'
156
                             'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
157
                             'data 6\n'
158
                             'second'
159
                             '\n'
160
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
161
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
162
                             'mark :4\n'
163
                             'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
164
                             'data 5\n'
165
                             'third'
166
                             '\n'
167
                             'from :2\n'
168
                             '\n', stream.getvalue())
169
170
    def test_commit_merge(self):
171
        stream = StringIO()
172
        builder = tests.GitBranchBuilder(stream)
173
174
        builder.set_file(u'foo', 'contents\nfoo\n', False)
175
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
176
                            timestamp=1194586400)
177
        r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
178
                            timestamp=1194586405)
179
        r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
180
                            timestamp=1194586410,
181
                            base=r1)
182
        r4 = builder.commit('Joe Foo <joe@foo.com>', u'Merge',
183
                            timestamp=1194586415,
184
                            merge=[r2])
185
186
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
187
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
188
                             'mark :2\n'
189
                             'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
190
                             'data 5\n'
191
                             'first'
192
                             '\n'
193
                             'M 100644 :1 foo\n'
194
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
195
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
196
                             'mark :3\n'
197
                             'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
198
                             'data 6\n'
199
                             'second'
200
                             '\n'
201
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
202
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
203
                             'mark :4\n'
204
                             'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
205
                             'data 5\n'
206
                             'third'
207
                             '\n'
208
                             'from :2\n'
209
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
210
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
211
                             'mark :5\n'
212
                             'committer Joe Foo <joe@foo.com> 1194586415 +0000\n'
213
                             'data 5\n'
214
                             'Merge'
215
                             '\n'
216
                             'merge :3\n'
217
                             '\n', stream.getvalue())
218
219
    def test_auto_timestamp(self):
220
        stream = StringIO()
221
        builder = tests.GitBranchBuilder(stream)
222
        builder.commit('Joe Foo <joe@foo.com>', u'message')
223
        self.assertContainsRe(stream.getvalue(),
224
                              r'committer Joe Foo <joe@foo\.com> \d+ \+0000')
225
0.200.34 by David Allouche
GitBranchBuilder.reset()
226
    def test_reset(self):
227
        stream = StringIO()
228
        builder = tests.GitBranchBuilder(stream)
229
        builder.reset()
230
        self.assertEqualDiff('reset refs/heads/master\n\n', stream.getvalue())
231
232
    def test_reset_named_ref(self):
233
        stream = StringIO()
234
        builder = tests.GitBranchBuilder(stream)
235
        builder.reset('refs/heads/branch')
236
        self.assertEqualDiff('reset refs/heads/branch\n\n', stream.getvalue())
237
238
    def test_reset_revision(self):
239
        stream = StringIO()
240
        builder = tests.GitBranchBuilder(stream)
241
        builder.reset(mark=123)
242
        self.assertEqualDiff(
243
            'reset refs/heads/master\n'
244
            'from :123\n'
245
            '\n', stream.getvalue())
246
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
247
248
class TestGitBranchBuilderReal(tests.TestCaseInTempDir):
249
250
    def test_create_real_branch(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
251
        GitRepo.init(".")
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
252
253
        builder = tests.GitBranchBuilder()
254
        builder.set_file(u'foo', 'contents\nfoo\n', False)
255
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
256
                            timestamp=1194586400)
257
        mapping = builder.finish()
0.200.1044 by Jelmer Vernooij
Fix fastexport-based tests.
258
        self.assertEqual({'1':'44411e8e9202177dd19b6599d7a7991059fa3cb4',
259
                          '2': 'b0b62e674f67306fddcf72fa888c3b56df100d64',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
260
                         }, mapping)