1
# Copyright (C) 2009 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
"""Tests for GitShaMap."""
21
from bzrlib.tests import (
27
from bzrlib.plugins.git.shamap import (
35
def test_commit(self):
36
self.map.start_write_group()
37
self.map.add_entries("myrevid", [],
38
"5686645d49063c73d35436192dfc9a160c672301",
39
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba", [])
40
self.map.commit_write_group()
42
("commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba")),
43
self.map.lookup_git_sha("5686645d49063c73d35436192dfc9a160c672301"))
45
def test_lookup_notfound(self):
46
self.assertRaises(KeyError,
47
self.map.lookup_git_sha, "5686645d49063c73d35436192dfc9a160c672301")
50
thesha = "9686645d49063c73d35436192dfc9a160c672301"
51
self.map.start_write_group()
52
self.map.add_entries("myrevid", [],
53
"5686645d49063c73d35436192dfc9a160c672301",
54
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba", [
55
("myfileid", "blob", thesha, "myrevid")
57
self.map.commit_write_group()
59
("blob", ("myfileid", "myrevid")),
60
self.map.lookup_git_sha(thesha))
61
invshamap = self.map.get_inventory_sha_map("myrevid")
62
self.assertEquals(thesha,
63
invshamap.lookup_blob_id("myfileid", "myrevid"))
66
thesha = "8686645d49063c73d35436192dfc9a160c672301"
67
self.map.start_write_group()
68
self.map.add_entries("myrevid", [],
69
"5686645d49063c73d35436192dfc9a160c672301",
70
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba", [
71
("somepath", "tree", thesha, "myrevid")])
72
self.map.commit_write_group()
74
("tree", ("somepath", "myrevid")),
75
self.map.lookup_git_sha(thesha))
77
def test_revids(self):
78
self.map.start_write_group()
79
self.map.add_entries("myrevid", [],
80
"5686645d49063c73d35436192dfc9a160c672301",
81
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba", [])
82
self.map.commit_write_group()
83
self.assertEquals(["myrevid"], list(self.map.revids()))
85
def test_missing_revisions(self):
86
self.map.start_write_group()
87
self.map.add_entries("myrevid", [],
88
"5686645d49063c73d35436192dfc9a160c672301",
89
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba", [])
90
self.map.commit_write_group()
91
self.assertEquals(set(["lala", "bla"]),
92
set(self.map.missing_revisions(["myrevid", "lala", "bla"])))
95
class DictGitShaMapTests(TestCase,TestGitShaMap):
99
self.map = DictGitShaMap()
102
class SqliteGitShaMapTests(TestCase,TestGitShaMap):
106
self.map = SqliteGitShaMap()
109
class TdbGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
112
TestCaseInTempDir.setUp(self)
114
self.map = TdbGitShaMap(os.path.join(self.test_dir, 'foo.tdb'))
116
raise UnavailableFeature("Missing tdb")