1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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
17
from dulwich.objects import (
21
from bzrlib.plugins.git import tests
22
from bzrlib.plugins.git.mapping import (
30
class TestRevidConversionV1(tests.TestCase):
32
def test_simple_git_to_bzr_revision_id(self):
33
self.assertEqual("git-v1:"
34
"c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
35
BzrGitMappingv1().revision_id_foreign_to_bzr(
36
"c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
38
def test_simple_bzr_to_git_revision_id(self):
39
self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
41
BzrGitMappingv1().revision_id_bzr_to_foreign(
43
"c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
46
class FileidTests(tests.TestCase):
48
def test_escape_space(self):
49
self.assertEquals("bla_s", escape_file_id("bla "))
51
def test_escape_underscore(self):
52
self.assertEquals("bla__", escape_file_id("bla_"))
54
def test_escape_underscore_space(self):
55
self.assertEquals("bla___s", escape_file_id("bla_ "))
57
def test_unescape_underscore(self):
58
self.assertEquals("bla ", unescape_file_id("bla_s"))
60
def test_unescape_underscore_space(self):
61
self.assertEquals("bla _", unescape_file_id("bla_s__"))
64
class TestImportCommit(tests.TestCase):
66
def test_commit(self):
68
c._tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
69
c._message = "Some message"
70
c._committer = "Committer"
75
rev = BzrGitMappingv1().import_commit(c)
76
self.assertEquals("Some message", rev.message)
77
self.assertEquals("Committer", rev.committer)
78
self.assertEquals("Author", rev.properties['author'])
79
self.assertEquals(0, rev.timezone)
80
self.assertEquals((), rev.parent_ids)
81
self.assertEquals("5", rev.properties['author-timestamp'])
82
self.assertEquals("git-v1:" + c.id, rev.revision_id)
86
class RoundtripRevisionsFromGit(tests.TestCase):
89
super(RoundtripRevisionsFromGit, self).setUp()
90
self.mapping = BzrGitMappingv1()
92
def assertRoundtripTree(self, tree):
93
raise NotImplementedError(self.assertRoundtripTree)
95
def assertRoundtripBlob(self, blob):
96
raise NotImplementedError(self.assertRoundtripBlob)
98
def assertRoundtripCommit(self, commit1):
100
rev = self.mapping.import_commit(commit1)
101
commit2 = revision_to_commit(rev, "12341212121212", None)
102
self.assertEquals(commit1.committer, commit2.committer)
103
self.assertEquals(commit1.commit_time, commit2.commit_time)
104
self.assertEquals(commit1.author, commit2.author)
105
self.assertEquals(commit1.author_time, commit2.author_time)
106
self.assertEquals(commit1.message, commit2.message)
108
def test_commit(self):
110
c._tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
111
c._message = "Some message"
112
c._committer = "Committer"
116
self.assertRoundtripCommit(c)