/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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Test our ability to build up test repositories"""
18
19
from cStringIO import StringIO
20
21
from bzrlib.plugins.git import tests
22
23
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
24
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.
25
26
    def test__create_blob(self):
27
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
28
        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.
29
        self.assertEqual(1, builder._create_blob('foo\nbar\n'))
30
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
31
                             stream.getvalue())
32
33
    def test_set_file(self):
34
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
35
        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.
36
        builder.set_file('foobar', 'foo\nbar\n', False)
37
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
38
                             stream.getvalue())
39
        self.assertEqual(['M 100644 :1 foobar\n'], builder.commit_info)
40
41
    def test_set_file_unicode(self):
42
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
43
        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.
44
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
45
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
46
                             stream.getvalue())
47
        self.assertEqual(['M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info)
48
49
    def test_set_file_executable(self):
50
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
51
        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.
52
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', True)
53
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
54
                             stream.getvalue())
55
        self.assertEqual(['M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info)
56
57
    def test_set_link(self):
58
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
59
        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.
60
        builder.set_link(u'f\xb5/bar', 'link/contents')
61
        self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
62
                             stream.getvalue())
63
        self.assertEqual(['M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info)
64
65
    def test_delete_entry(self):
66
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
67
        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.
68
        builder.delete_entry(u'path/to/f\xb5')
69
        self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info)
70
71
    def test_add_and_commit(self):
72
        stream = StringIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
73
        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.
74
75
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
76
        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.
77
                                           u'committing f\xb5/bar',
78
                                           timestamp=1194586400,
79
                                           timezone='+0100'))
80
        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.
81
                             '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.
82
                             'mark :2\n'
83
                             'committer Joe Foo <joe@foo.com> 1194586400 +0100\n'
84
                             'data 18\n'
85
                             'committing f\xc2\xb5/bar'
86
                             '\n'
87
                             'M 100644 :1 f\xc2\xb5/bar\n'
88
                             '\n',
89
                             stream.getvalue())
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
90
91
    def test_commit_base(self):
92
        stream = StringIO()
93
        builder = tests.GitBranchBuilder(stream)
94
95
        builder.set_file(u'foo', 'contents\nfoo\n', False)
96
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
97
                            timestamp=1194586400)
98
        r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
99
                            timestamp=1194586405)
100
        r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
101
                            timestamp=1194586410,
102
                            base=r1)
103
104
        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.
105
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
106
                             'mark :2\n'
107
                             'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
108
                             'data 5\n'
109
                             'first'
110
                             '\n'
111
                             'M 100644 :1 foo\n'
112
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
113
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
114
                             'mark :3\n'
115
                             'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
116
                             'data 6\n'
117
                             'second'
118
                             '\n'
119
                             '\n'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
120
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
121
                             'mark :4\n'
122
                             'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
123
                             'data 5\n'
124
                             'third'
125
                             '\n'
126
                             'from :2\n'
127
                             '\n', stream.getvalue())
128
129
    def test_commit_merge(self):
130
        stream = StringIO()
131
        builder = tests.GitBranchBuilder(stream)
132
133
        builder.set_file(u'foo', 'contents\nfoo\n', False)
134
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
135
                            timestamp=1194586400)
136
        r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
137
                            timestamp=1194586405)
138
        r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
139
                            timestamp=1194586410,
140
                            base=r1)
141
        r4 = builder.commit('Joe Foo <joe@foo.com>', u'Merge',
142
                            timestamp=1194586415,
143
                            merge=[r2])
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'
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
169
                             'commit refs/heads/master\n'
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
170
                             'mark :5\n'
171
                             'committer Joe Foo <joe@foo.com> 1194586415 +0000\n'
172
                             'data 5\n'
173
                             'Merge'
174
                             '\n'
175
                             'merge :3\n'
176
                             '\n', stream.getvalue())
177
178
    def test_auto_timestamp(self):
179
        stream = StringIO()
180
        builder = tests.GitBranchBuilder(stream)
181
        builder.commit('Joe Foo <joe@foo.com>', u'message')
182
        self.assertContainsRe(stream.getvalue(),
183
                              r'committer Joe Foo <joe@foo\.com> \d+ \+0000')
184
0.200.34 by David Allouche
GitBranchBuilder.reset()
185
    def test_reset(self):
186
        stream = StringIO()
187
        builder = tests.GitBranchBuilder(stream)
188
        builder.reset()
189
        self.assertEqualDiff('reset refs/heads/master\n\n', stream.getvalue())
190
191
    def test_reset_named_ref(self):
192
        stream = StringIO()
193
        builder = tests.GitBranchBuilder(stream)
194
        builder.reset('refs/heads/branch')
195
        self.assertEqualDiff('reset refs/heads/branch\n\n', stream.getvalue())
196
197
    def test_reset_revision(self):
198
        stream = StringIO()
199
        builder = tests.GitBranchBuilder(stream)
200
        builder.reset(mark=123)
201
        self.assertEqualDiff(
202
            'reset refs/heads/master\n'
203
            'from :123\n'
204
            '\n', stream.getvalue())
205
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
206
207
class TestGitBranchBuilderReal(tests.TestCaseInTempDir):
208
209
    def test_create_real_branch(self):
210
        tests.run_git('init')
211
212
        builder = tests.GitBranchBuilder()
213
        builder.set_file(u'foo', 'contents\nfoo\n', False)
214
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
215
                            timestamp=1194586400)
216
        mapping = builder.finish()
217
        self.assertEqual({1:'44411e8e9202177dd19b6599d7a7991059fa3cb4',
218
                          2: 'b0b62e674f67306fddcf72fa888c3b56df100d64',
219
                         }, mapping)