/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
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
0.200.56 by Jelmer Vernooij
Switch to using GitPython rather than our own in-house stuff.
19
import git
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
20
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
21
from bzrlib import (
0.200.61 by Jelmer Vernooij
Fix tests.
22
    errors,
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
23
    inventory,
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
24
    repository,
25
    revision,
26
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
27
28
from bzrlib.plugins.git import tests
0.200.27 by David Allouche
Flat is better than nested, remove the gitlib hierarchy.
29
from bzrlib.plugins.git import (
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
30
    git_dir,
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
31
    git_repository,
0.200.21 by John Arbash Meinel
Fix Repository.get_revision_graph()
32
    ids,
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
33
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
34
35
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
36
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
37
    """Feature tests for GitRepository."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
38
39
    _test_needs_features = [tests.GitCommandFeature]
40
41
    def test_open_existing(self):
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
42
        tests.run_git('init')
43
44
        repo = repository.Repository.open('.')
45
        self.assertIsInstance(repo, git_repository.GitRepository)
46
0.200.56 by Jelmer Vernooij
Switch to using GitPython rather than our own in-house stuff.
47
    def test_has_git_repo(self):
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
48
        tests.run_git('init')
49
50
        repo = repository.Repository.open('.')
0.200.56 by Jelmer Vernooij
Switch to using GitPython rather than our own in-house stuff.
51
        self.assertIsInstance(repo._git, git.repo.Repo)
0.200.21 by John Arbash Meinel
Fix Repository.get_revision_graph()
52
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
53
    def test_get_revision(self):
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
54
        # GitRepository.get_revision gives a Revision object.
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
55
56
        # Create a git repository with a revision.
57
        tests.run_git('init')
58
        builder = tests.GitBranchBuilder()
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
59
        builder.set_file('a', 'text for a\n', False)
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
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 = ids.convert_revision_id_git_to_bzr(commit_id)
66
        repo = repository.Repository.open('.')
67
        rev = repo.get_revision(revid)
68
        self.assertIsInstance(rev, revision.Revision)
0.200.32 by David Allouche
Rewrite GitRepository._parse_rev, with unit tests.
69
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
70
    def test_get_inventory(self):
71
        # GitRepository.get_inventory gives a GitInventory object with
72
        # plausible entries for typical cases.
73
74
        # Create a git repository with some interesting files in a revision.
75
        tests.run_git('init')
76
        builder = tests.GitBranchBuilder()
77
        builder.set_file('data', 'text\n', False)
78
        builder.set_file('executable', 'content', True)
79
        builder.set_link('link', 'broken')
80
        builder.set_file('subdir/subfile', 'subdir text\n', False)
0.204.4 by James Westby
Make the inventory test match what the code produces.
81
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message',
82
            timestamp=1205433193)
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
83
        mapping = builder.finish()
84
        commit_id = mapping[commit_handle]
85
86
        # Get the corresponding Inventory object.
87
        revid = ids.convert_revision_id_git_to_bzr(commit_id)
88
        repo = repository.Repository.open('.')
89
        inv = repo.get_inventory(revid)
90
        self.assertIsInstance(inv, inventory.Inventory)
91
        printed_inv = '\n'.join(
92
            repr((path, entry.executable, entry))
93
            for path, entry in inv.iter_entries())
94
        self.assertEqualDiff(
95
            printed_inv,
96
            "('', False, InventoryDirectory('TREE_ROOT', u'', parent_id=None,"
0.204.4 by James Westby
Make the inventory test match what the code produces.
97
            " revision='git-experimental-r:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
98
            "(u'data', False, InventoryFile('data', u'data',"
99
            " parent_id='TREE_ROOT',"
0.204.4 by James Westby
Make the inventory test match what the code produces.
100
            " sha1='aa785adca3fcdfe1884ae840e13c6d294a2414e8', len=5))\n"
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
101
            "(u'executable', True, InventoryFile('executable', u'executable',"
102
            " parent_id='TREE_ROOT',"
0.204.4 by James Westby
Make the inventory test match what the code produces.
103
            " sha1='040f06fd774092478d450774f5ba30c5da78acc8', len=7))\n"
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
104
            "(u'link', False, InventoryLink('link', u'link',"
0.204.4 by James Westby
Make the inventory test match what the code produces.
105
            " parent_id='TREE_ROOT', revision='git-experimental-r:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
106
            "(u'subdir', False, InventoryDirectory('subdir', u'subdir',"
0.204.4 by James Westby
Make the inventory test match what the code produces.
107
            " parent_id='TREE_ROOT', revision='git-experimental-r:69c39cfa65962f3cf16b9b3eb08a15954e9d8590'))\n"
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
108
            "(u'subdir/subfile', False, InventoryFile('subdir/subfile',"
109
            " u'subfile', parent_id='subdir',"
0.204.4 by James Westby
Make the inventory test match what the code produces.
110
            " sha1='67b75c3e49f31fcadddbf9df6a1d8be8c3e44290', len=12))")
0.200.38 by David Allouche
Reimplement GitRepository.get_inventory, simpler and faster.
111
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
112
0.204.2 by James Westby
Switch to TestCaseWithTransport so that the cache dir can be
113
class TestGitRepository(tests.TestCaseWithTransport):
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
114
115
    def setUp(self):
0.204.2 by James Westby
Switch to TestCaseWithTransport so that the cache dir can be
116
        tests.TestCaseWithTransport.setUp(self)
0.200.57 by Jelmer Vernooij
Fix more tests.
117
        git.repo.Repo.create(self.test_dir)
118
        self.git_repo = repository.Repository.open(self.test_dir)
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
119
0.200.40 by David Allouche
GitRepository.supports_rich_root() => False
120
    def test_supports_rich_root(self):
121
        # GitRepository.supports_rich_root is False, at least for now.
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
122
        repo = self.git_repo
0.200.40 by David Allouche
GitRepository.supports_rich_root() => False
123
        self.assertEqual(repo.supports_rich_root(), False)
124
0.200.60 by Jelmer Vernooij
Support signature functions.
125
    def test_get_signature_text(self):
0.200.61 by Jelmer Vernooij
Fix tests.
126
        self.assertRaises(errors.NoSuchRevision, self.git_repo.get_signature_text, revision.NULL_REVISION)
0.200.60 by Jelmer Vernooij
Support signature functions.
127
128
    def test_has_signature_for_revision_id(self):
129
        self.assertEquals(False, self.git_repo.has_signature_for_revision_id(revision.NULL_REVISION))
130
0.200.65 by Jelmer Vernooij
Implement get_ancestry properly.
131
    def test_get_ancestry_null(self):
132
        self.assertEquals([None], self.git_repo.get_ancestry(revision.NULL_REVISION))
133
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
134
    def assertIsNullInventory(self, inv):
135
        self.assertEqual(inv.root, None)
136
        self.assertEqual(inv.revision_id, revision.NULL_REVISION)
137
        self.assertEqual(list(inv.iter_entries()), [])
138
139
    def test_get_inventory_none(self):
140
        # GitRepository.get_inventory(None) returns the null inventory.
141
        repo = self.git_repo
0.200.57 by Jelmer Vernooij
Fix more tests.
142
        inv = repo.get_inventory(revision.NULL_REVISION)
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
143
        self.assertIsNullInventory(inv)
144
145
    def test_revision_tree_none(self):
146
        # GitRepository.revision_tree(None) returns the null tree.
147
        repo = self.git_repo
0.200.57 by Jelmer Vernooij
Fix more tests.
148
        tree = repo.revision_tree(revision.NULL_REVISION)
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
149
        self.assertEqual(tree.get_revision_id(), revision.NULL_REVISION)
150
        self.assertIsNullInventory(tree.inventory)
151
0.200.71 by Jelmer Vernooij
Implement GitRepositoryFormat.get_format_description.
152
153
class GitRepositoryFormat(tests.TestCase):
154
155
    def setUp(self):
156
        super(GitRepositoryFormat, self).setUp()
157
        self.format = git_repository.GitFormat()
158
159
    def test_get_format_description(self):
160
        self.assertEquals("Git Repository", self.format.get_format_description())