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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-13 23:16:57 UTC
  • mfrom: (1662.1.1 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060413231657-bce3d67d3e7a4f2b
(mbp/olaf) push/pull/merge --remember improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
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
 
"""Black-box tests for bzr-git."""
18
 
 
19
 
from dulwich.repo import (
20
 
    Repo as GitRepo,
21
 
    )
22
 
 
23
 
import os
24
 
 
25
 
from .... import (
26
 
    version_info as breezy_version,
27
 
    )
28
 
from ....controldir import (
29
 
    ControlDir,
30
 
    )
31
 
 
32
 
from ....tests.blackbox import ExternalBase
33
 
 
34
 
from .. import (
35
 
    tests,
36
 
    )
37
 
 
38
 
 
39
 
class TestGitBlackBox(ExternalBase):
40
 
 
41
 
    def simple_commit(self):
42
 
        # Create a git repository with a revision.
43
 
        repo = GitRepo.init(self.test_dir)
44
 
        builder = tests.GitBranchBuilder()
45
 
        builder.set_file('a', 'text for a\n', False)
46
 
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
47
 
        return repo, builder.finish()[r1]
48
 
 
49
 
    def test_nick(self):
50
 
        r = GitRepo.init(self.test_dir)
51
 
        del r["HEAD"]
52
 
        dir = ControlDir.open(self.test_dir)
53
 
        dir.create_branch()
54
 
        output, error = self.run_bzr(['nick'])
55
 
        self.assertEquals("HEAD\n", output)
56
 
 
57
 
    def test_info(self):
58
 
        self.simple_commit()
59
 
        output, error = self.run_bzr(['info'])
60
 
        self.assertEqual(error, '')
61
 
        self.assertTrue("Standalone tree (format: git)" in output)
62
 
 
63
 
    def test_branch(self):
64
 
        os.mkdir("gitbranch")
65
 
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
66
 
        os.chdir('gitbranch')
67
 
        builder = tests.GitBranchBuilder()
68
 
        builder.set_file('a', 'text for a\n', False)
69
 
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
70
 
        builder.finish()
71
 
        os.chdir('..')
72
 
 
73
 
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
74
 
        self.assertTrue(
75
 
            (error == 'Branched 1 revision(s).\n') or
76
 
            (error == 'Branched 1 revision.\n'),
77
 
            error)
78
 
 
79
 
    def test_checkout(self):
80
 
        os.mkdir("gitbranch")
81
 
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
82
 
        os.chdir('gitbranch')
83
 
        builder = tests.GitBranchBuilder()
84
 
        builder.set_file('a', 'text for a\n', False)
85
 
        builder.commit('Joe Foo <joe@foo.com>', u'<The commit message>')
86
 
        builder.finish()
87
 
        os.chdir('..')
88
 
 
89
 
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
90
 
        self.assertEqual(error, '')
91
 
        self.assertEqual(output, '')
92
 
 
93
 
    def test_branch_ls(self):
94
 
        self.simple_commit()
95
 
        output, error = self.run_bzr(['ls', '-r-1'])
96
 
        self.assertEqual(error, '')
97
 
        self.assertEqual(output, "a\n")
98
 
 
99
 
    def test_init(self):
100
 
        self.run_bzr("init --format=git repo")
101
 
 
102
 
    def test_info_verbose(self):
103
 
        self.simple_commit()
104
 
 
105
 
        output, error = self.run_bzr(['info', '-v'])
106
 
        self.assertEqual(error, '')
107
 
        self.assertTrue("Standalone tree (format: git)" in output)
108
 
        self.assertTrue("control: Local Git Repository" in output)
109
 
        self.assertTrue("branch: Git Branch" in output)
110
 
        self.assertTrue("repository: Git Repository" in output)
111
 
 
112
 
    def test_push_roundtripping(self):
113
 
        self.knownFailure("roundtripping is not yet supported")
114
 
        self.with_roundtripping()
115
 
        os.mkdir("bla")
116
 
        GitRepo.init(os.path.join(self.test_dir, "bla"))
117
 
        self.run_bzr(['init', 'foo'])
118
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
119
 
        # when roundtripping is supported
120
 
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
121
 
        self.assertEquals("", output)
122
 
        self.assertTrue(error.endswith("Created new branch.\n"))
123
 
 
124
 
    def test_log(self):
125
 
        # Smoke test for "bzr log" in a git repository.
126
 
        self.simple_commit()
127
 
 
128
 
        # Check that bzr log does not fail and includes the revision.
129
 
        output, error = self.run_bzr(['log'])
130
 
        self.assertEqual(error, '')
131
 
        self.assertTrue(
132
 
            '<The commit message>' in output,
133
 
            "Commit message was not found in output:\n%s" % (output,))
134
 
 
135
 
    def test_log_verbose(self):
136
 
        # Smoke test for "bzr log -v" in a git repository.
137
 
        self.simple_commit()
138
 
 
139
 
        # Check that bzr log does not fail and includes the revision.
140
 
        output, error = self.run_bzr(['log', '-v'])
141
 
 
142
 
    def test_tags(self):
143
 
        git_repo, commit_sha1 = self.simple_commit()
144
 
        git_repo.refs["refs/tags/foo"] = commit_sha1
145
 
 
146
 
        output, error = self.run_bzr(['tags'])
147
 
        self.assertEquals(error, '')
148
 
        self.assertEquals(output, "foo                  1\n")
149
 
 
150
 
    def test_tag(self):
151
 
        self.simple_commit()
152
 
 
153
 
        output, error = self.run_bzr(["tag", "bar"])
154
 
 
155
 
        # bzr <= 2.2 emits this message in the output stream
156
 
        # bzr => 2.3 emits this message in the error stream
157
 
        self.assertEquals(error + output, 'Created tag bar.\n')
158
 
 
159
 
    def test_init_repo(self):
160
 
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
161
 
        self.assertEquals(error, '')
162
 
        self.assertEquals(output, 'Created a standalone tree (format: git)\n')
163
 
 
164
 
    def test_diff_format(self):
165
 
        tree = self.make_branch_and_tree('.')
166
 
        self.build_tree(['a'])
167
 
        tree.add(['a'])
168
 
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
169
 
        self.assertEqual(error, '')
170
 
        self.assertEqual(output,
171
 
            'diff --git /dev/null b/a\n'
172
 
            'old mode 0\n'
173
 
            'new mode 100644\n'
174
 
            'index 0000000..c197bd8 100644\n'
175
 
            '--- /dev/null\n'
176
 
            '+++ b/a\n'
177
 
            '@@ -1,0 +1,1 @@\n'
178
 
            '+contents of a\n')
179
 
 
180
 
    def test_git_import_uncolocated(self):
181
 
        r = GitRepo.init("a", mkdir=True)
182
 
        self.build_tree(["a/file"])
183
 
        r.stage("file")
184
 
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
185
 
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
186
 
        self.run_bzr(["git-import", "a", "b"])
187
 
        self.assertEquals(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
188
 
 
189
 
    def test_git_import(self):
190
 
        r = GitRepo.init("a", mkdir=True)
191
 
        self.build_tree(["a/file"])
192
 
        r.stage("file")
193
 
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
194
 
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
195
 
        self.run_bzr(["git-import", "--colocated", "a", "b"])
196
 
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
197
 
        self.assertEquals(set(["abranch", "bbranch"]),
198
 
                set(ControlDir.open("b").get_branches().keys()))
199
 
 
200
 
    def test_git_import_incremental(self):
201
 
        r = GitRepo.init("a", mkdir=True)
202
 
        self.build_tree(["a/file"])
203
 
        r.stage("file")
204
 
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
205
 
        self.run_bzr(["git-import", "--colocated", "a", "b"])
206
 
        self.run_bzr(["git-import", "--colocated", "a", "b"])
207
 
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
208
 
        b = ControlDir.open("b")
209
 
        self.assertEquals(["abranch"], b.get_branches().keys())
210
 
 
211
 
    def test_git_import_tags(self):
212
 
        r = GitRepo.init("a", mkdir=True)
213
 
        self.build_tree(["a/file"])
214
 
        r.stage("file")
215
 
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
216
 
        r["refs/tags/atag"] = cid
217
 
        self.run_bzr(["git-import", "--colocated", "a", "b"])
218
 
        self.assertEquals(set([".bzr"]), set(os.listdir("b")))
219
 
        b = ControlDir.open("b")
220
 
        self.assertEquals(["abranch"], b.get_branches().keys())
221
 
        self.assertEquals(["atag"],
222
 
                b.open_branch("abranch").tags.get_tag_dict().keys())
223
 
 
224
 
    def test_git_import_colo(self):
225
 
        r = GitRepo.init("a", mkdir=True)
226
 
        self.build_tree(["a/file"])
227
 
        r.stage("file")
228
 
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
229
 
        r.do_commit(ref="refs/heads/bbranch", committer="Joe <joe@example.com>", message="Dummy")
230
 
        self.make_controldir("b", format="development-colo")
231
 
        self.run_bzr(["git-import", "--colocated", "a", "b"])
232
 
        self.assertEquals(
233
 
            set([b.name for b in ControlDir.open("b").list_branches()]),
234
 
            set(["abranch", "bbranch"]))
235
 
 
236
 
    def test_git_refs_from_git(self):
237
 
        r = GitRepo.init("a", mkdir=True)
238
 
        self.build_tree(["a/file"])
239
 
        r.stage("file")
240
 
        cid = r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
241
 
        r["refs/tags/atag"] = cid
242
 
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
243
 
        self.assertEquals(stderr, "")
244
 
        self.assertEquals(stdout,
245
 
            'refs/tags/atag -> ' + cid + '\n'
246
 
            'refs/heads/abranch -> ' + cid + '\n')
247
 
 
248
 
    def test_git_refs_from_bzr(self):
249
 
        tree = self.make_branch_and_tree('a')
250
 
        self.build_tree(["a/file"])
251
 
        tree.add(["file"])
252
 
        revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
253
 
        tree.branch.tags.set_tag("atag", revid)
254
 
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
255
 
        self.assertEquals(stderr, "")
256
 
        self.assertTrue("refs/tags/atag -> " in stdout)
257
 
        self.assertTrue("HEAD -> " in stdout)
258
 
 
259
 
    def test_dpush(self):
260
 
        r = GitRepo.init("gitr", mkdir=True)
261
 
        self.build_tree_contents([("gitr/foo", "hello from git")])
262
 
        r.stage("foo")
263
 
        r.do_commit("message", committer="Somebody <user@example.com>")
264
 
        self.run_bzr(["branch", "gitr", "bzrb"])
265
 
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
266
 
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
267
 
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])
268
 
 
269
 
    def test_dpush_from_bound(self):
270
 
        r = GitRepo.init("gitr", mkdir=True)
271
 
        self.build_tree_contents([("gitr/foo", "hello from git")])
272
 
        r.stage("foo")
273
 
        r.do_commit("message", committer="Somebody <user@example.com>")
274
 
        self.run_bzr(["branch", "gitr", "bzrm"])
275
 
        self.run_bzr(["checkout", "bzrm", "bzrb"])
276
 
        self.build_tree_contents([("bzrb/foo", "hello from bzr")])
277
 
        self.run_bzr(["commit", "-m", "msg", "bzrb"])
278
 
        self.run_bzr(["dpush", "-d", "bzrb", "gitr"])