/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

Tags: bzr-git-0.1.0
Add tests for GitShaMap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
 
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
import os
 
18
 
 
19
from bzrlib.bzrdir import BzrDir
 
20
from bzrlib.repository import Repository
 
21
from bzrlib.tests import TestCaseWithTransport
 
22
 
 
23
from bzrlib.plugins.git import (
 
24
    get_rich_root_format,
 
25
    )
 
26
from bzrlib.plugins.git.fetch import BzrFetchGraphWalker
 
27
from bzrlib.plugins.git.mapping import default_mapping
 
28
from bzrlib.plugins.git.tests import (
 
29
    GitBranchBuilder,
 
30
    run_git,
 
31
    )
 
32
 
 
33
 
 
34
class FetchGraphWalkerTests(TestCaseWithTransport):
 
35
 
 
36
    def setUp(self):
 
37
        TestCaseWithTransport.setUp(self)
 
38
        self.mapping = default_mapping
 
39
 
 
40
    def test_empty(self):
 
41
        tree = self.make_branch_and_tree("wt")
 
42
        graphwalker = BzrFetchGraphWalker(tree.branch.repository, self.mapping)
 
43
        self.assertEquals(None, graphwalker.next())
 
44
 
 
45
 
 
46
class LocalRepositoryFetchTests(TestCaseWithTransport):
 
47
 
 
48
    def make_git_repo(self, path):
 
49
        os.mkdir(path)
 
50
        os.chdir(path)
 
51
        run_git("init")
 
52
        os.chdir("..")
 
53
 
 
54
    def clone_git_repo(self, from_url, to_url):
 
55
        oldrepos = Repository.open(from_url)
 
56
        dir = BzrDir.create(to_url, get_rich_root_format())
 
57
        newrepos = dir.create_repository()
 
58
        oldrepos.copy_content_into(newrepos)
 
59
        return newrepos
 
60
 
 
61
    def test_empty(self):
 
62
        self.make_git_repo("d")
 
63
        newrepos = self.clone_git_repo("d", "f")
 
64
        self.assertEquals([], newrepos.all_revision_ids())
 
65
 
 
66
    def test_single_rev(self):
 
67
        self.make_git_repo("d")
 
68
        os.chdir("d")
 
69
        bb = GitBranchBuilder()
 
70
        bb.set_file("foobar", "foo\nbar\n", False)
 
71
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
72
        gitsha = bb.finish()[mark]
 
73
        os.chdir("..")
 
74
        oldrepo = Repository.open("d")
 
75
        newrepo = self.clone_git_repo("d", "f")
 
76
        self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids())
 
77
 
 
78
    def test_executable(self):
 
79
        self.make_git_repo("d")
 
80
        os.chdir("d")
 
81
        bb = GitBranchBuilder()
 
82
        bb.set_file("foobar", "foo\nbar\n", True)
 
83
        bb.set_file("notexec", "foo\nbar\n", False)
 
84
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
85
        gitsha = bb.finish()[mark]
 
86
        os.chdir("..")
 
87
        oldrepo = Repository.open("d")
 
88
        newrepo = self.clone_git_repo("d", "f")
 
89
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
90
        tree = newrepo.revision_tree(revid)
 
91
        self.assertTrue(tree.has_filename("foobar"))
 
92
        self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable)
 
93
        self.assertTrue(tree.has_filename("notexec"))
 
94
        self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)