/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: Jelmer Vernooij
  • Date: 2018-04-02 14:59:43 UTC
  • mto: (0.200.1913 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180402145943-s5jmpbvvf1x42pao
Just don't touch the URL if it's already a valid URL.

Show diffs side-by-side

added added

removed removed

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