/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_fetch.py

Add more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.plugins.git.fetch import BzrFetchGraphWalker
18
 
from bzrlib.plugins.git.mapping import default_mapping
19
 
 
20
 
from bzrlib.tests import TestCaseWithTransport
 
17
from dulwich.objects import (
 
18
    Blob,
 
19
    )
 
20
import os
 
21
 
 
22
from bzrlib import (
 
23
    knit,
 
24
    versionedfile,
 
25
    )
 
26
from bzrlib.bzrdir import (
 
27
    BzrDir,
 
28
    )
 
29
from bzrlib.inventory import (
 
30
    Inventory,
 
31
    )
 
32
from bzrlib.repository import (
 
33
    Repository,
 
34
    )
 
35
from bzrlib.tests import (
 
36
    TestCaseWithTransport,
 
37
    )
 
38
from bzrlib.transport import (
 
39
    get_transport,
 
40
    )
 
41
 
 
42
from bzrlib.plugins.git import (
 
43
    get_rich_root_format,
 
44
    )
 
45
from bzrlib.plugins.git.fetch import (
 
46
    BzrFetchGraphWalker,
 
47
    import_git_blob,
 
48
    import_git_tree,
 
49
    )
 
50
from bzrlib.plugins.git.mapping import (
 
51
    BzrGitMappingv1,
 
52
    default_mapping,
 
53
    )
 
54
from bzrlib.plugins.git.shamap import (
 
55
    DictGitShaMap,
 
56
    )
 
57
from bzrlib.plugins.git.tests import (
 
58
    GitBranchBuilder,
 
59
    run_git,
 
60
    )
 
61
 
21
62
 
22
63
class FetchGraphWalkerTests(TestCaseWithTransport):
23
64
 
31
72
        self.assertEquals(None, graphwalker.next())
32
73
 
33
74
 
 
75
class LocalRepositoryFetchTests(TestCaseWithTransport):
 
76
 
 
77
    def make_git_repo(self, path):
 
78
        os.mkdir(path)
 
79
        os.chdir(path)
 
80
        run_git("init")
 
81
        os.chdir("..")
 
82
 
 
83
    def clone_git_repo(self, from_url, to_url):
 
84
        oldrepos = Repository.open(from_url)
 
85
        dir = BzrDir.create(to_url, get_rich_root_format())
 
86
        newrepos = dir.create_repository()
 
87
        oldrepos.copy_content_into(newrepos)
 
88
        return newrepos
 
89
 
 
90
    def test_empty(self):
 
91
        self.make_git_repo("d")
 
92
        newrepos = self.clone_git_repo("d", "f")
 
93
        self.assertEquals([], newrepos.all_revision_ids())
 
94
 
 
95
    def test_single_rev(self):
 
96
        self.make_git_repo("d")
 
97
        os.chdir("d")
 
98
        bb = GitBranchBuilder()
 
99
        bb.set_file("foobar", "foo\nbar\n", False)
 
100
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
101
        gitsha = bb.finish()[mark]
 
102
        os.chdir("..")
 
103
        oldrepo = Repository.open("d")
 
104
        newrepo = self.clone_git_repo("d", "f")
 
105
        self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids())
 
106
 
 
107
    def test_executable(self):
 
108
        self.make_git_repo("d")
 
109
        os.chdir("d")
 
110
        bb = GitBranchBuilder()
 
111
        bb.set_file("foobar", "foo\nbar\n", True)
 
112
        bb.set_file("notexec", "foo\nbar\n", False)
 
113
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
114
        gitsha = bb.finish()[mark]
 
115
        os.chdir("..")
 
116
        oldrepo = Repository.open("d")
 
117
        newrepo = self.clone_git_repo("d", "f")
 
118
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
119
        tree = newrepo.revision_tree(revid)
 
120
        self.assertTrue(tree.has_filename("foobar"))
 
121
        self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable)
 
122
        self.assertTrue(tree.has_filename("notexec"))
 
123
        self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)
 
124
 
 
125
 
 
126
class ImportObjects(TestCaseWithTransport):
 
127
 
 
128
    def setUp(self):
 
129
        super(ImportObjects, self).setUp()
 
130
        self._map = DictGitShaMap()
 
131
        factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
 
132
        self._texts = factory(self.get_transport('texts'))
 
133
 
 
134
    def test_import_blob_simple(self):
 
135
        blob = Blob.from_string("bar")
 
136
        inv = Inventory()
 
137
        inv.revision_id = "somerevid"
 
138
        import_git_blob(self._texts, BzrGitMappingv1(), "bla", blob, 
 
139
            inv, [], self._map, False)
 
140
        self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys())