/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import os

from bzrlib.bzrdir import BzrDir
from bzrlib.repository import Repository
from bzrlib.tests import TestCaseWithTransport

from bzrlib.plugins.git import (
    get_rich_root_format,
    )
from bzrlib.plugins.git.fetch import BzrFetchGraphWalker
from bzrlib.plugins.git.mapping import default_mapping
from bzrlib.plugins.git.tests import (
    GitBranchBuilder,
    run_git,
    )


class FetchGraphWalkerTests(TestCaseWithTransport):

    def setUp(self):
        TestCaseWithTransport.setUp(self)
        self.mapping = default_mapping

    def test_empty(self):
        tree = self.make_branch_and_tree("wt")
        graphwalker = BzrFetchGraphWalker(tree.branch.repository, self.mapping)
        self.assertEquals(None, graphwalker.next())


class LocalRepositoryFetchTests(TestCaseWithTransport):

    def make_git_repo(self, path):
        os.mkdir(path)
        os.chdir(path)
        run_git("init")
        os.chdir("..")

    def clone_git_repo(self, from_url, to_url):
        oldrepos = Repository.open(from_url)
        dir = BzrDir.create(to_url, get_rich_root_format())
        newrepos = dir.create_repository()
        oldrepos.copy_content_into(newrepos)
        return newrepos

    def test_empty(self):
        self.make_git_repo("d")
        newrepos = self.clone_git_repo("d", "f")
        self.assertEquals([], newrepos.all_revision_ids())

    def test_single_rev(self):
        self.make_git_repo("d")
        os.chdir("d")
        bb = GitBranchBuilder()
        bb.set_file("foobar", "foo\nbar\n", False)
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
        gitsha = bb.finish()[mark]
        os.chdir("..")
        oldrepo = Repository.open("d")
        newrepo = self.clone_git_repo("d", "f")
        self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids())

    def test_executable(self):
        self.make_git_repo("d")
        os.chdir("d")
        bb = GitBranchBuilder()
        bb.set_file("foobar", "foo\nbar\n", True)
        bb.set_file("notexec", "foo\nbar\n", False)
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
        gitsha = bb.finish()[mark]
        os.chdir("..")
        oldrepo = Repository.open("d")
        newrepo = self.clone_git_repo("d", "f")
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
        tree = newrepo.revision_tree(revid)
        self.assertTrue(tree.has_filename("foobar"))
        self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable)
        self.assertTrue(tree.has_filename("notexec"))
        self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable)