/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 breezy/plugins/git/tests/test_blackbox.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-03 03:20:44 UTC
  • mfrom: (7018.3.10 git-fixes)
  • Revision ID: breezy.the.bot@gmail.com-20180703032044-t5a5w5y0tmzrbezc
Port a few more bits of the git plugin to python 3.

Merged from https://code.launchpad.net/~jelmer/brz/git-fixes2/+merge/348803

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        # Create a git repository with a revision.
46
46
        repo = GitRepo.init(self.test_dir)
47
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>')
 
48
        builder.set_file('a', b'text for a\n', False)
 
49
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
50
50
        return repo, builder.finish()[r1]
51
51
 
52
52
    def test_nick(self):
64
64
    def test_info(self):
65
65
        self.simple_commit()
66
66
        output, error = self.run_bzr(['info'])
67
 
        self.assertEqual(error, '')
 
67
        self.assertEqual(error, b'')
68
68
        self.assertTrue(b"Standalone tree (format: git)" in output)
69
69
 
70
70
    def test_branch(self):
95
95
 
96
96
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
97
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, '')
 
98
                b'Fetching from Git to Bazaar repository. '
 
99
                b'For better performance, fetch into a Git repository.\n')
 
100
        self.assertEqual(output, b'')
101
101
 
102
102
    def test_branch_ls(self):
103
103
        self.simple_commit()
104
104
        output, error = self.run_bzr(['ls', '-r-1'])
105
 
        self.assertEqual(error, '')
106
 
        self.assertEqual(output, "a\n")
 
105
        self.assertEqual(error, b'')
 
106
        self.assertEqual(output, b"a\n")
107
107
 
108
108
    def test_init(self):
109
109
        self.run_bzr("init --format=git repo")
112
112
        self.simple_commit()
113
113
 
114
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)
 
115
        self.assertEqual(error, b'')
 
116
        self.assertTrue(b"Standalone tree (format: git)" in output)
 
117
        self.assertTrue(b"control: Local Git Repository" in output)
 
118
        self.assertTrue(b"branch: Local Git Branch" in output)
 
119
        self.assertTrue(b"repository: Git Repository" in output)
120
120
 
121
121
    def test_push_roundtripping(self):
122
122
        self.knownFailure("roundtripping is not yet supported")
127
127
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
128
128
        # when roundtripping is supported
129
129
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
130
 
        self.assertEqual("", output)
131
 
        self.assertTrue(error.endswith("Created new branch.\n"))
 
130
        self.assertEqual(b"", output)
 
131
        self.assertTrue(error.endswith(b"Created new branch.\n"))
132
132
 
133
133
    def test_log(self):
134
134
        # Smoke test for "bzr log" in a git repository.
136
136
 
137
137
        # Check that bzr log does not fail and includes the revision.
138
138
        output, error = self.run_bzr(['log'])
139
 
        self.assertEqual(error, '')
 
139
        self.assertEqual(error, b'')
140
140
        self.assertTrue(
141
 
            '<The commit message>' in output,
142
 
            "Commit message was not found in output:\n%s" % (output,))
 
141
            b'<The commit message>' in output,
 
142
            b"Commit message was not found in output:\n%s" % (output,))
143
143
 
144
144
    def test_log_verbose(self):
145
145
        # Smoke test for "bzr log -v" in a git repository.
147
147
 
148
148
        # Check that bzr log does not fail and includes the revision.
149
149
        output, error = self.run_bzr(['log', '-v'])
150
 
 
 
150
 
151
151
    def test_tags(self):
152
152
        git_repo, commit_sha1 = self.simple_commit()
153
 
        git_repo.refs["refs/tags/foo"] = commit_sha1
 
153
        git_repo.refs[b"refs/tags/foo"] = commit_sha1
154
154
 
155
155
        output, error = self.run_bzr(['tags'])
156
 
        self.assertEqual(error, '')
157
 
        self.assertEqual(output, "foo                  1\n")
 
156
        self.assertEqual(error, b'')
 
157
        self.assertEqual(output, b"foo                  1\n")
158
158
 
159
159
    def test_tag(self):
160
160
        self.simple_commit()
163
163
 
164
164
        # bzr <= 2.2 emits this message in the output stream
165
165
        # bzr => 2.3 emits this message in the error stream
166
 
        self.assertEqual(error + output, 'Created tag bar.\n')
 
166
        self.assertEqual(error + output, b'Created tag bar.\n')
167
167
 
168
168
    def test_init_repo(self):
169
169
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
190
190
        r = GitRepo.init("a", mkdir=True)
191
191
        self.build_tree(["a/file"])
192
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")
 
193
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
194
        r.do_commit(ref=b"refs/heads/bbranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
195
195
        self.run_bzr(["git-import", "a", "b"])
196
196
        self.assertEqual(set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
197
197
 
199
199
        r = GitRepo.init("a", mkdir=True)
200
200
        self.build_tree(["a/file"])
201
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")
 
202
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
203
        r.do_commit(ref=b"refs/heads/bbranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
204
204
        self.run_bzr(["git-import", "--colocated", "a", "b"])
205
205
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
206
206
        self.assertEqual(set(["abranch", "bbranch"]),
210
210
        r = GitRepo.init("a", mkdir=True)
211
211
        self.build_tree(["a/file"])
212
212
        r.stage("file")
213
 
        r.do_commit(ref="refs/heads/abranch", committer="Joe <joe@example.com>", message="Dummy")
 
213
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
214
214
        self.run_bzr(["git-import", "--colocated", "a", "b"])
215
215
        self.run_bzr(["git-import", "--colocated", "a", "b"])
216
216
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
221
221
        r = GitRepo.init("a", mkdir=True)
222
222
        self.build_tree(["a/file"])
223
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
 
224
        cid = r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
225
        r[b"refs/tags/atag"] = cid
226
226
        self.run_bzr(["git-import", "--colocated", "a", "b"])
227
227
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
228
228
        b = ControlDir.open("b")
234
234
        r = GitRepo.init("a", mkdir=True)
235
235
        self.build_tree(["a/file"])
236
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")
 
237
        r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
238
        r.do_commit(ref=b"refs/heads/bbranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
239
239
        self.make_controldir("b", format="development-colo")
240
240
        self.run_bzr(["git-import", "--colocated", "a", "b"])
241
241
        self.assertEqual(
246
246
        r = GitRepo.init("a", mkdir=True)
247
247
        self.build_tree(["a/file"])
248
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
 
249
        cid = r.do_commit(ref=b"refs/heads/abranch", committer=b"Joe <joe@example.com>", message=b"Dummy")
 
250
        r[b"refs/tags/atag"] = cid
251
251
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
252
252
        self.assertEqual(stderr, b"")
253
253
        self.assertEqual(stdout,
254
 
            b'refs/tags/atag -> ' + cid + b'\n'
255
 
            b'refs/heads/abranch -> ' + cid + b'\n')
 
254
            b'refs/heads/abranch -> ' + cid + b'\n'
 
255
            b'refs/tags/atag -> ' + cid + b'\n')
256
256
 
257
257
    def test_git_refs_from_bzr(self):
258
258
        tree = self.make_branch_and_tree('a')
259
259
        self.build_tree(["a/file"])
260
260
        tree.add(["file"])
261
 
        revid = tree.commit(committer="Joe <joe@example.com>", message="Dummy")
 
261
        revid = tree.commit(committer=b"Joe <joe@example.com>", message=b"Dummy")
262
262
        tree.branch.tags.set_tag("atag", revid)
263
263
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
264
264
        self.assertEqual(stderr, b"")
267
267
 
268
268
    def test_check(self):
269
269
        r = GitRepo.init("gitr", mkdir=True)
270
 
        self.build_tree_contents([("gitr/foo", "hello from git")])
 
270
        self.build_tree_contents([("gitr/foo", b"hello from git")])
271
271
        r.stage("foo")
272
 
        r.do_commit("message", committer="Somebody <user@example.com>")
 
272
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
273
273
        out, err = self.run_bzr(["check", "gitr"])
274
274
        self.maxDiff = None
275
 
        self.assertMultiLineEqual(out, b'')
 
275
        self.assertEqual(out, b'')
276
276
        self.assertTrue(err.endswith, b'3 objects\n')
277
277
 
278
278
 
282
282
        super(ShallowTests, self).setUp()
283
283
        # Smoke test for "bzr log" in a git repository with shallow depth.
284
284
        self.repo = GitRepo.init('gitr', mkdir=True)
285
 
        self.build_tree_contents([("gitr/foo", "hello from git")])
 
285
        self.build_tree_contents([("gitr/foo", b"hello from git")])
286
286
        self.repo.stage("foo")
287
287
        self.repo.do_commit(
288
 
                "message", committer="Somebody <user@example.com>",
 
288
                b"message", committer=b"Somebody <user@example.com>",
289
289
                commit_timestamp=1526330165, commit_timezone=0,
290
290
                author_timestamp=1526330165, author_timezone=0,
291
291
                merge_heads=[b'aa' * 20])
293
293
    def test_log_shallow(self):
294
294
        # Check that bzr log does not fail and includes the revision.
295
295
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
296
 
        self.assertEqual(error, 'brz: ERROR: Further revision history missing.\n')
 
296
        self.assertEqual(error, b'brz: ERROR: Further revision history missing.\n')
297
297
        self.assertEqual(output,
298
298
                b'------------------------------------------------------------\n'
299
299
                b'revision-id: git-v1:' + self.repo.head() + b'\n'