/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_repository.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-08 21:56:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3773.
  • Revision ID: john@arbash-meinel.com-20081008215612-y9v94tqxreqoangx
Simplify the --raw mode.

I didn't realize, but the only node that is special cased is the 'root' node,
and to read it, you actually have to parse it directly, because the
compressed bytes start immediately after the end of the header, rather than
having any padding before the zlib bytes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
"""Tests for interfacing with a Git Repository"""
18
 
 
19
 
import git
20
 
 
21
 
from bzrlib import (
22
 
    errors,
23
 
    inventory,
24
 
    revision,
25
 
    )
26
 
from bzrlib.repository import Repository
27
 
 
28
 
from bzrlib.plugins.git import (
29
 
    dir,
30
 
    repository,
31
 
    tests,
32
 
    )
33
 
from bzrlib.plugins.git.mapping import default_mapping
34
 
 
35
 
 
36
 
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
37
 
    """Feature tests for GitRepository."""
38
 
 
39
 
    _test_needs_features = [tests.GitCommandFeature]
40
 
 
41
 
    def test_open_existing(self):
42
 
        tests.run_git('init')
43
 
 
44
 
        repo = Repository.open('.')
45
 
        self.assertIsInstance(repo, repository.GitRepository)
46
 
 
47
 
    def test_has_git_repo(self):
48
 
        tests.run_git('init')
49
 
 
50
 
        repo = Repository.open('.')
51
 
        self.assertIsInstance(repo._git, git.repo.Repo)
52
 
 
53
 
    def test_get_revision(self):
54
 
        # GitRepository.get_revision gives a Revision object.
55
 
 
56
 
        # Create a git repository with a revision.
57
 
        tests.run_git('init')
58
 
        builder = tests.GitBranchBuilder()
59
 
        builder.set_file('a', 'text for a\n', False)
60
 
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
61
 
        mapping = builder.finish()
62
 
        commit_id = mapping[commit_handle]
63
 
 
64
 
        # Get the corresponding Revision object.
65
 
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
66
 
        repo = Repository.open('.')
67
 
        rev = repo.get_revision(revid)
68
 
        self.assertIsInstance(rev, revision.Revision)
69
 
 
70
 
    def test_get_revision_unknown(self):
71
 
        tests.run_git('init')
72
 
 
73
 
        repo = Repository.open('.')
74
 
        self.assertRaises(errors.NoSuchRevision, repo.get_revision, "bla")
75
 
 
76
 
    def simple_commit(self):
77
 
        # Create a git repository with some interesting files in a revision.
78
 
        tests.run_git('init')
79
 
        builder = tests.GitBranchBuilder()
80
 
        builder.set_file('data', 'text\n', False)
81
 
        builder.set_file('executable', 'content', True)
82
 
        builder.set_link('link', 'broken')
83
 
        builder.set_file('subdir/subfile', 'subdir text\n', False)
84
 
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message',
85
 
            timestamp=1205433193)
86
 
        mapping = builder.finish()
87
 
        return mapping[commit_handle]
88
 
 
89
 
    def test_revision_tree(self):
90
 
        commit_id = self.simple_commit()
91
 
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
92
 
        repo = Repository.open('.')
93
 
        tree = repo.revision_tree(revid)
94
 
        self.assertEquals(tree.get_revision_id(), revid)
95
 
        self.assertEquals("text\n", tree.get_file_text(tree.path2id("data")))
96
 
 
97
 
    def test_get_inventory(self):
98
 
        # GitRepository.get_inventory gives a GitInventory object with
99
 
        # plausible entries for typical cases.
100
 
 
101
 
        commit_id = self.simple_commit()
102
 
 
103
 
        # Get the corresponding Inventory object.
104
 
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
105
 
        repo = Repository.open('.')
106
 
        inv = repo.get_inventory(revid)
107
 
        self.assertIsInstance(inv, inventory.Inventory)
108
 
        printed_inv = '\n'.join(
109
 
            repr((path, entry.executable, entry))
110
 
            for path, entry in inv.iter_entries())
111
 
        self.assertEqualDiff(
112
 
            printed_inv,
113
 
            "('', False, InventoryDirectory('TREE_ROOT', u'', parent_id=None,"
114
 
            " revision='git-experimental:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
115
 
            "(u'data', False, InventoryFile('data', u'data',"
116
 
            " parent_id='TREE_ROOT',"
117
 
            " sha1='aa785adca3fcdfe1884ae840e13c6d294a2414e8', len=5))\n"
118
 
            "(u'executable', True, InventoryFile('executable', u'executable',"
119
 
            " parent_id='TREE_ROOT',"
120
 
            " sha1='040f06fd774092478d450774f5ba30c5da78acc8', len=7))\n"
121
 
            "(u'link', False, InventoryLink('link', u'link',"
122
 
            " parent_id='TREE_ROOT', revision='git-experimental:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
123
 
            "(u'subdir', False, InventoryDirectory('subdir', u'subdir',"
124
 
            " parent_id='TREE_ROOT', revision='git-experimental:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
125
 
            "(u'subdir/subfile', False, InventoryFile('subdir/subfile',"
126
 
            " u'subfile', parent_id='subdir',"
127
 
            " sha1='67b75c3e49f31fcadddbf9df6a1d8be8c3e44290', len=12))")
128
 
 
129
 
 
130
 
class TestGitRepository(tests.TestCaseWithTransport):
131
 
 
132
 
    def setUp(self):
133
 
        tests.TestCaseWithTransport.setUp(self)
134
 
        git.repo.Repo.create(self.test_dir)
135
 
        self.git_repo = Repository.open(self.test_dir)
136
 
 
137
 
    def test_supports_rich_root(self):
138
 
        # GitRepository.supports_rich_root is False, at least for now.
139
 
        repo = self.git_repo
140
 
        self.assertEqual(repo.supports_rich_root(), False)
141
 
 
142
 
    def test_get_signature_text(self):
143
 
        self.assertRaises(errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION)
144
 
 
145
 
    def test_has_signature_for_revision_id(self):
146
 
        self.assertEquals(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION))
147
 
 
148
 
    def test_all_revision_ids_none(self):
149
 
        self.assertEquals(set(), self.git_repo.all_revision_ids())
150
 
 
151
 
    def test_get_ancestry_null(self):
152
 
        self.assertEquals([None], self.git_repo.get_ancestry(revision.NULL_REVISION))
153
 
 
154
 
    def assertIsNullInventory(self, inv):
155
 
        self.assertEqual(inv.root, None)
156
 
        self.assertEqual(inv.revision_id, revision.NULL_REVISION)
157
 
        self.assertEqual(list(inv.iter_entries()), [])
158
 
 
159
 
    def test_get_inventory_none(self):
160
 
        # GitRepository.get_inventory(None) returns the null inventory.
161
 
        repo = self.git_repo
162
 
        inv = repo.get_inventory(revision.NULL_REVISION)
163
 
        self.assertIsNullInventory(inv)
164
 
 
165
 
    def test_revision_tree_none(self):
166
 
        # GitRepository.revision_tree(None) returns the null tree.
167
 
        repo = self.git_repo
168
 
        tree = repo.revision_tree(revision.NULL_REVISION)
169
 
        self.assertEqual(tree.get_revision_id(), revision.NULL_REVISION)
170
 
        self.assertIsNullInventory(tree.inventory)
171
 
 
172
 
    def test_get_parent_map_null(self):
173
 
        self.assertEquals({revision.NULL_REVISION: ()}, 
174
 
                           self.git_repo.get_parent_map([revision.NULL_REVISION]))
175
 
 
176
 
 
177
 
class GitRepositoryFormat(tests.TestCase):
178
 
 
179
 
    def setUp(self):
180
 
        super(GitRepositoryFormat, self).setUp()
181
 
        self.format = repository.GitFormat()
182
 
 
183
 
    def test_get_format_description(self):
184
 
        self.assertEquals("Git Repository", self.format.get_format_description())