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"
73
c.commit_timezone = 60 * 5
74
c.author_timezone = 60 * 3
77
rev = BzrGitMappingv1().import_commit(c)
78
self.assertEquals("Some message", rev.message)
79
self.assertEquals("Committer", rev.committer)
80
self.assertEquals("Author", rev.properties['author'])
81
self.assertEquals(300, rev.timezone)
82
self.assertEquals((), rev.parent_ids)
83
self.assertEquals("5", rev.properties['author-timestamp'])
84
self.assertEquals("180", rev.properties['author-timezone'])
85
self.assertEquals("git-v1:" + c.id, rev.revision_id)
89
class RoundtripRevisionsFromGit(tests.TestCase):
92
super(RoundtripRevisionsFromGit, self).setUp()
93
self.mapping = BzrGitMappingv1()
95
def assertRoundtripTree(self, tree):
96
raise NotImplementedError(self.assertRoundtripTree)
98
def assertRoundtripBlob(self, blob):
99
raise NotImplementedError(self.assertRoundtripBlob)
101
def assertRoundtripCommit(self, commit1):
103
rev = self.mapping.import_commit(commit1)
104
commit2 = revision_to_commit(rev, "12341212121212", None)
105
self.assertEquals(commit1.committer, commit2.committer)
106
self.assertEquals(commit1.commit_time, commit2.commit_time)
107
self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
108
self.assertEquals(commit1.author, commit2.author)
109
self.assertEquals(commit1.author_time, commit2.author_time)
110
self.assertEquals(commit1.author_timezone, commit2.author_timezone)
111
self.assertEquals(commit1.message, commit2.message)
113
def test_commit(self):
115
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
116
c.message = "Some message"
117
c.committer = "Committer <Committer>"
119
c.commit_timezone = -60 * 3
121
c.author_timezone = 60 * 2
122
c.author = "Author <author>"
123
self.assertRoundtripCommit(c)