21
21
from bzrlib.plugins.git import tests
24
class TestCommitBuilder(tests.TestCase):
24
class TestGitBranchBuilder(tests.TestCase):
26
26
def test__create_blob(self):
27
27
stream = StringIO()
28
builder = tests.GitCommitBuilder(stream)
28
builder = tests.GitBranchBuilder(stream)
29
29
self.assertEqual(1, builder._create_blob('foo\nbar\n'))
30
30
self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
33
33
def test_set_file(self):
34
34
stream = StringIO()
35
builder = tests.GitCommitBuilder(stream)
35
builder = tests.GitBranchBuilder(stream)
36
36
builder.set_file('foobar', 'foo\nbar\n', False)
37
37
self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
65
65
def test_delete_entry(self):
66
66
stream = StringIO()
67
builder = tests.GitCommitBuilder(stream)
67
builder = tests.GitBranchBuilder(stream)
68
68
builder.delete_entry(u'path/to/f\xb5')
69
69
self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info)
71
71
def test_add_and_commit(self):
72
72
stream = StringIO()
73
builder = tests.GitCommitBuilder(stream)
73
builder = tests.GitBranchBuilder(stream)
75
75
builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
76
self.assertEqual(2, builder.commit('refs/head/master',
77
'Joe Foo <joe@foo.com>',
76
self.assertEqual(2, builder.commit('Joe Foo <joe@foo.com>',
78
77
u'committing f\xb5/bar',
79
78
timestamp=1194586400,
88
87
'M 100644 :1 f\xc2\xb5/bar\n'
91
def test_commit_base(self):
93
builder = tests.GitBranchBuilder(stream)
95
builder.set_file(u'foo', 'contents\nfoo\n', False)
96
r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
98
r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
100
r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
101
timestamp=1194586410,
104
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
105
'commit refs/head/master\n'
107
'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
113
'commit refs/head/master\n'
115
'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
120
'commit refs/head/master\n'
122
'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
127
'\n', stream.getvalue())
129
def test_commit_merge(self):
131
builder = tests.GitBranchBuilder(stream)
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,
141
r4 = builder.commit('Joe Foo <joe@foo.com>', u'Merge',
142
timestamp=1194586415,
145
self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
146
'commit refs/head/master\n'
148
'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
154
'commit refs/head/master\n'
156
'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
161
'commit refs/head/master\n'
163
'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
169
'commit refs/head/master\n'
171
'committer Joe Foo <joe@foo.com> 1194586415 +0000\n'
176
'\n', stream.getvalue())
178
def test_auto_timestamp(self):
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')
186
class TestGitBranchBuilderReal(tests.TestCaseInTempDir):
188
def test_create_real_branch(self):
189
tests.run_git('init')
191
builder = tests.GitBranchBuilder()
192
builder.set_file(u'foo', 'contents\nfoo\n', False)
193
r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
194
timestamp=1194586400)
195
mapping = builder.finish()
196
self.assertEqual({1:'44411e8e9202177dd19b6599d7a7991059fa3cb4',
197
2: 'b0b62e674f67306fddcf72fa888c3b56df100d64',