/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:
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
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
    )
17
26
from bzrlib.plugins.git.fetch import BzrFetchGraphWalker
18
27
from bzrlib.plugins.git.mapping import default_mapping
 
28
from bzrlib.plugins.git.tests import (
 
29
    GitBranchBuilder,
 
30
    run_git,
 
31
    )
19
32
 
20
 
from bzrlib.tests import TestCaseWithTransport
21
33
 
22
34
class FetchGraphWalkerTests(TestCaseWithTransport):
23
35
 
31
43
        self.assertEquals(None, graphwalker.next())
32
44
 
33
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)