/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
19
import subprocess
20
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
21
from bzrlib import (
22
    repository,
23
    revision,
24
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
25
26
from bzrlib.plugins.git import tests
0.200.27 by David Allouche
Flat is better than nested, remove the gitlib hierarchy.
27
from bzrlib.plugins.git import (
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
28
    git_repository,
0.200.21 by John Arbash Meinel
Fix Repository.get_revision_graph()
29
    ids,
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
30
    model,
31
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
32
33
34
class TestGitRepository(tests.TestCaseInTempDir):
35
36
    _test_needs_features = [tests.GitCommandFeature]
37
38
    def test_open_existing(self):
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
39
        tests.run_git('init')
40
41
        repo = repository.Repository.open('.')
42
        self.assertIsInstance(repo, git_repository.GitRepository)
43
44
    def test_has_git_model(self):
45
        tests.run_git('init')
46
47
        repo = repository.Repository.open('.')
48
        self.assertIsInstance(repo._git, model.GitModel)
0.200.21 by John Arbash Meinel
Fix Repository.get_revision_graph()
49
50
    def test_revision_graph(self):
51
        tests.run_git('init')
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
52
        builder = tests.GitBranchBuilder()
0.200.31 by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value.
53
        builder.set_file('a', 'text for a\n', False)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
54
        commit1_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
0.200.31 by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value.
55
        builder.set_file('a', 'new a\n', False)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
56
        commit2_handle = builder.commit('Joe Foo <joe@foo.com>', u'new a')
0.200.31 by David Allouche
GitBranchBuilder.set_file returns None, do not save its return value.
57
        builder.set_file('b', 'text for b\n', False)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
58
        commit3_handle = builder.commit('Jerry Bar <jerry@foo.com>', u'b',
59
                                        base=commit1_handle)
60
        commit4_handle = builder.commit('Jerry Bar <jerry@foo.com>', u'merge',
61
                                        base=commit3_handle,
62
                                        merge=[commit2_handle],)
63
64
        mapping = builder.finish()
65
        commit1_id = mapping[commit1_handle]
66
        commit2_id = mapping[commit2_handle]
67
        commit3_id = mapping[commit3_handle]
68
        commit4_id = mapping[commit4_handle]
69
70
        revisions = tests.run_git('rev-list', '--topo-order',
71
                                  commit4_id)
72
        revisions = revisions.splitlines()
73
        self.assertEqual([commit4_id, commit2_id, commit3_id, commit1_id],
74
                         revisions)
75
        bzr_revisions = [ids.convert_revision_id_git_to_bzr(r) for r in revisions]
76
        graph = {bzr_revisions[0]:[bzr_revisions[2], bzr_revisions[1]],
77
                 bzr_revisions[1]:[bzr_revisions[3]],
78
                 bzr_revisions[2]:[bzr_revisions[3]],
79
                 bzr_revisions[3]:[],
0.200.21 by John Arbash Meinel
Fix Repository.get_revision_graph()
80
                }
81
82
        repo = repository.Repository.open('.')
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
83
        self.assertEqual(graph, repo.get_revision_graph(bzr_revisions[0]))
84
        self.assertEqual({bzr_revisions[3]:[]},
85
                         repo.get_revision_graph(bzr_revisions[3]))
0.200.29 by David Allouche
Smoke test for GitRepository.get_revision, and corresponding fixes.
86
87
    def test_get_revision(self):
88
        # Test that GitRepository.get_revision gives a Revision object.
89
90
        # Create a git repository with a revision.
91
        tests.run_git('init')
92
        builder = tests.GitBranchBuilder()
93
        file_handle = builder.set_file('a', 'text for a\n', False)
94
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
95
        mapping = builder.finish()
96
        commit_id = mapping[commit_handle]
97
98
        # Get the corresponding Revision object.
99
        revid = ids.convert_revision_id_git_to_bzr(commit_id)
100
        repo = repository.Repository.open('.')
101
        rev = repo.get_revision(revid)
102
        self.assertIsInstance(rev, revision.Revision)