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

Add simple HACKING document.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for interfacing with a Git Branch"""
18
18
 
19
 
import git
20
 
 
21
 
from bzrlib import branch, revision
22
 
 
23
 
from bzrlib.plugins.git import tests
 
19
import dulwich as git
 
20
import os
 
21
 
 
22
from bzrlib import (
 
23
    revision,
 
24
    )
 
25
from bzrlib.branch import (
 
26
    Branch,
 
27
    )
 
28
from bzrlib.bzrdir import (
 
29
    BzrDir,
 
30
    )
 
31
from bzrlib.repository import (
 
32
    Repository,
 
33
    )
 
34
 
24
35
from bzrlib.plugins.git import (
25
 
    git_branch,
26
 
    ids,
 
36
    branch,
 
37
    tests,
27
38
    )
 
39
from bzrlib.plugins.git.mapping import default_mapping
28
40
 
29
41
 
30
42
class TestGitBranch(tests.TestCaseInTempDir):
34
46
    def test_open_existing(self):
35
47
        tests.run_git('init')
36
48
 
37
 
        thebranch = branch.Branch.open('.')
38
 
        self.assertIsInstance(thebranch, git_branch.GitBranch)
 
49
        thebranch = Branch.open('.')
 
50
        self.assertIsInstance(thebranch, branch.GitBranch)
39
51
 
40
52
    def test_last_revision_is_null(self):
41
53
        tests.run_git('init')
42
54
 
43
 
        thebranch = branch.Branch.open('.')
 
55
        thebranch = Branch.open('.')
44
56
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
45
57
        self.assertEqual((0, revision.NULL_REVISION),
46
58
                         thebranch.last_revision_info())
47
59
 
 
60
    def simple_commit_a(self):
 
61
        tests.run_git('init')
 
62
        self.build_tree(['a'])
 
63
        tests.run_git('add', 'a')
 
64
        tests.run_git('commit', '-m', 'a')
 
65
 
48
66
    def test_last_revision_is_valid(self):
49
 
        tests.run_git('init')
50
 
        self.build_tree(['a'])
51
 
        tests.run_git('add', 'a')
52
 
        tests.run_git('commit', '-m', 'a')
 
67
        self.simple_commit_a()
53
68
        head = tests.run_git('rev-parse', 'HEAD').strip()
54
69
 
55
 
        thebranch = branch.Branch.open('.')
56
 
        self.assertEqual(ids.convert_revision_id_git_to_bzr(head),
 
70
        thebranch = Branch.open('.')
 
71
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
57
72
                         thebranch.last_revision())
58
73
 
59
74
    def test_revision_history(self):
60
 
        tests.run_git('init')
61
 
        self.build_tree(['a'])
62
 
        tests.run_git('add', 'a')
63
 
        tests.run_git('commit', '-m', 'a')
 
75
        self.simple_commit_a()
64
76
        reva = tests.run_git('rev-parse', 'HEAD').strip()
65
77
        self.build_tree(['b'])
66
78
        tests.run_git('add', 'b')
67
79
        tests.run_git('commit', '-m', 'b')
68
80
        revb = tests.run_git('rev-parse', 'HEAD').strip()
69
81
 
70
 
        thebranch = branch.Branch.open('.')
71
 
        self.assertEqual([ids.convert_revision_id_git_to_bzr(r) for r in (reva, revb)],
 
82
        thebranch = Branch.open('.')
 
83
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
72
84
                         thebranch.revision_history())
 
85
 
 
86
    def test_tag_annotated(self):
 
87
        self.simple_commit_a()
 
88
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
89
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
 
90
        thebranch = Branch.open('.')
 
91
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
 
92
                          thebranch.tags.get_tag_dict())
 
93
 
 
94
    def test_tag(self):
 
95
        self.simple_commit_a()
 
96
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
97
        tests.run_git('tag', '-m', 'add tag', 'foo')
 
98
        thebranch = Branch.open('.')
 
99
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
 
100
                          thebranch.tags.get_tag_dict())
 
101
 
73
102
        
74
103
 
75
104
class TestWithGitBranch(tests.TestCaseWithTransport):
77
106
    def setUp(self):
78
107
        tests.TestCaseWithTransport.setUp(self)
79
108
        git.repo.Repo.create(self.test_dir)
80
 
        self.git_branch = branch.Branch.open(self.test_dir)
 
109
        self.git_branch = Branch.open(self.test_dir)
81
110
 
82
111
    def test_get_parent(self):
83
112
        self.assertIs(None, self.git_branch.get_parent())
93
122
 
94
123
    def setUp(self):
95
124
        super(TestGitBranchFormat, self).setUp()
96
 
        self.format = git_branch.GitBranchFormat()
 
125
        self.format = branch.GitBranchFormat()
97
126
 
98
127
    def test_get_format_description(self):
99
128
        self.assertEquals("Git Branch", self.format.get_format_description())
 
129
 
 
130
 
 
131
 
 
132
class BranchTests(tests.TestCaseInTempDir):
 
133
 
 
134
    def make_onerev_branch(self):
 
135
        os.mkdir("d")
 
136
        os.chdir("d")
 
137
        tests.run_git("init")
 
138
        bb = tests.GitBranchBuilder()
 
139
        bb.set_file("foobar", "foo\nbar\n", False)
 
140
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
141
        gitsha = bb.finish()[mark]
 
142
        os.chdir("..")
 
143
        return "d", gitsha
 
144
 
 
145
    def clone_git_branch(self, from_url, to_url):
 
146
        from_dir = BzrDir.open(from_url)
 
147
        to_dir = from_dir.sprout(to_url)
 
148
        return to_dir.open_branch()
 
149
 
 
150
    def test_single_rev(self):
 
151
        path, gitsha = self.make_onerev_branch()
 
152
        oldrepo = Repository.open(path)
 
153
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
154
        newbranch = self.clone_git_branch(path, "f")
 
155
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
 
156
 
 
157
    def test_sprouted_tags(self):
 
158
        path, gitsha = self.make_onerev_branch()
 
159
        os.chdir(path)
 
160
        tests.run_git("tag", "lala")
 
161
        os.chdir(self.test_dir)
 
162
        oldrepo = Repository.open(path)
 
163
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
164
        newbranch = self.clone_git_branch(path, "f")
 
165
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
 
166
        self.assertEquals([revid], newbranch.repository.all_revision_ids())