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

  • Committer: Jelmer Vernooij
  • Date: 2019-12-23 01:39:21 UTC
  • mfrom: (7424 work)
  • mto: This revision was merged to the branch mainline in revision 7425.
  • Revision ID: jelmer@jelmer.uk-20191223013921-2kzd0wlcoylgxksk
Merge trunk.

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 ...controldir import (
 
29
    ControlDir,
 
30
    )
 
31
 
 
32
from ...tests.blackbox import ExternalBase
 
33
from ...workingtree import WorkingTree
 
34
 
 
35
from .. import (
 
36
    tests,
 
37
    )
 
38
from ...tests.script import TestCaseWithTransportAndScript
 
39
from ...tests.features import PluginLoadedFeature
 
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', b'text for a\n', False)
 
49
        r1 = builder.commit(b'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.assertEqual("master\n", output)
 
58
 
 
59
    def test_branches(self):
 
60
        self.simple_commit()
 
61
        output, error = self.run_bzr(['branches'])
 
62
        self.assertEqual("* 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.assertEqual(
 
69
            output,
 
70
            'Standalone tree (format: git)\n'
 
71
            'Location:\n'
 
72
            '            light checkout root: .\n'
 
73
            '  checkout of co-located branch: master\n')
 
74
 
 
75
    def test_ignore(self):
 
76
        self.simple_commit()
 
77
        output, error = self.run_bzr(['ignore', 'foo'])
 
78
        self.assertEqual(error, '')
 
79
        self.assertEqual(output, '')
 
80
        self.assertFileEqual("foo\n", ".gitignore")
 
81
 
 
82
    def test_cat_revision(self):
 
83
        self.simple_commit()
 
84
        output, error = self.run_bzr(['cat-revision', '-r-1'], retcode=3)
 
85
        self.assertContainsRe(
 
86
            error,
 
87
            'brz: ERROR: Repository .* does not support access to raw '
 
88
            'revision texts')
 
89
        self.assertEqual(output, '')
 
90
 
 
91
    def test_branch(self):
 
92
        os.mkdir("gitbranch")
 
93
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
94
        os.chdir('gitbranch')
 
95
        builder = tests.GitBranchBuilder()
 
96
        builder.set_file(b'a', b'text for a\n', False)
 
97
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
 
98
        builder.finish()
 
99
        os.chdir('..')
 
100
 
 
101
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
 
102
        self.assertTrue(
 
103
            (error == 'Branched 1 revision(s).\n') or
 
104
            (error == 'Branched 1 revision.\n'),
 
105
            error)
 
106
 
 
107
    def test_checkout(self):
 
108
        os.mkdir("gitbranch")
 
109
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
110
        os.chdir('gitbranch')
 
111
        builder = tests.GitBranchBuilder()
 
112
        builder.set_file(b'a', b'text for a\n', False)
 
113
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
 
114
        builder.finish()
 
115
        os.chdir('..')
 
116
 
 
117
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
 
118
        self.assertEqual(error,
 
119
                         'Fetching from Git to Bazaar repository. '
 
120
                         'For better performance, fetch into a Git repository.\n')
 
121
        self.assertEqual(output, '')
 
122
 
 
123
    def test_branch_ls(self):
 
124
        self.simple_commit()
 
125
        output, error = self.run_bzr(['ls', '-r-1'])
 
126
        self.assertEqual(error, '')
 
127
        self.assertEqual(output, "a\n")
 
128
 
 
129
    def test_init(self):
 
130
        self.run_bzr("init --format=git repo")
 
131
 
 
132
    def test_info_verbose(self):
 
133
        self.simple_commit()
 
134
 
 
135
        output, error = self.run_bzr(['info', '-v'])
 
136
        self.assertEqual(error, '')
 
137
        self.assertTrue("Standalone tree (format: git)" in output)
 
138
        self.assertTrue("control: Local Git Repository" in output)
 
139
        self.assertTrue("branch: Local Git Branch" in output)
 
140
        self.assertTrue("repository: Git Repository" in output)
 
141
 
 
142
    def test_push_roundtripping(self):
 
143
        self.knownFailure("roundtripping is not yet supported")
 
144
        self.with_roundtripping()
 
145
        os.mkdir("bla")
 
146
        GitRepo.init(os.path.join(self.test_dir, "bla"))
 
147
        self.run_bzr(['init', 'foo'])
 
148
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
149
        # when roundtripping is supported
 
150
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
 
151
        self.assertEqual(b"", output)
 
152
        self.assertTrue(error.endswith(b"Created new branch.\n"))
 
153
 
 
154
    def test_push_without_calculate_revnos(self):
 
155
        self.run_bzr(['init', '--git', 'bla'])
 
156
        self.run_bzr(['init', '--git', 'foo'])
 
157
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
158
        output, error = self.run_bzr(
 
159
            ['push', '-Ocalculate_revnos=no', '-d', 'foo', 'bla'])
 
160
        self.assertEqual("", output)
 
161
        self.assertContainsRe(
 
162
            error,
 
163
            'Pushed up to revision id git(.*).\n')
 
164
 
 
165
    def test_push_lossy_non_mainline(self):
 
166
        self.run_bzr(['init', '--git', 'bla'])
 
167
        self.run_bzr(['init', 'foo'])
 
168
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
169
        self.run_bzr(['branch', 'foo', 'foo1'])
 
170
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
 
171
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
172
        self.run_bzr(['merge', '-d', 'foo', 'foo1'])
 
173
        self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
 
174
        output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
 
175
        self.assertEqual("", output)
 
176
        self.assertEqual(
 
177
            'Pushing from a Bazaar to a Git repository. For better '
 
178
            'performance, push into a Bazaar repository.\n'
 
179
            'All changes applied successfully.\n'
 
180
            'Pushed up to revision 2.\n', error)
 
181
 
 
182
    def test_log(self):
 
183
        # Smoke test for "bzr log" in a git repository.
 
184
        self.simple_commit()
 
185
 
 
186
        # Check that bzr log does not fail and includes the revision.
 
187
        output, error = self.run_bzr(['log'])
 
188
        self.assertEqual(error, '')
 
189
        self.assertTrue(
 
190
            '<The commit message>' in output,
 
191
            "Commit message was not found in output:\n%s" % (output,))
 
192
 
 
193
    def test_log_verbose(self):
 
194
        # Smoke test for "bzr log -v" in a git repository.
 
195
        self.simple_commit()
 
196
 
 
197
        # Check that bzr log does not fail and includes the revision.
 
198
        output, error = self.run_bzr(['log', '-v'])
 
199
        self.assertContainsRe(output, 'revno: 1')
 
200
 
 
201
    def test_log_without_revno(self):
 
202
        # Smoke test for "bzr log -v" in a git repository.
 
203
        self.simple_commit()
 
204
 
 
205
        # Check that bzr log does not fail and includes the revision.
 
206
        output, error = self.run_bzr(['log', '-Ocalculate_revnos=no'])
 
207
        self.assertNotContainsRe(output, 'revno: 1')
 
208
 
 
209
    def test_commit_without_revno(self):
 
210
        repo = GitRepo.init(self.test_dir)
 
211
        output, error = self.run_bzr(
 
212
            ['commit', '-Ocalculate_revnos=yes', '--unchanged', '-m', 'one'])
 
213
        self.assertContainsRe(error, 'Committed revision 1.')
 
214
        output, error = self.run_bzr(
 
215
            ['commit', '-Ocalculate_revnos=no', '--unchanged', '-m', 'two'])
 
216
        self.assertNotContainsRe(error, 'Committed revision 2.')
 
217
        self.assertContainsRe(error, 'Committed revid .*.')
 
218
 
 
219
    def test_log_file(self):
 
220
        # Smoke test for "bzr log" in a git repository.
 
221
        repo = GitRepo.init(self.test_dir)
 
222
        builder = tests.GitBranchBuilder()
 
223
        builder.set_file('a', b'text for a\n', False)
 
224
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'First')
 
225
        builder.set_file('a', b'text 3a for a\n', False)
 
226
        r2a = builder.commit(b'Joe Foo <joe@foo.com>', u'Second a', base=r1)
 
227
        builder.set_file('a', b'text 3b for a\n', False)
 
228
        r2b = builder.commit(b'Joe Foo <joe@foo.com>', u'Second b', base=r1)
 
229
        builder.set_file('a', b'text 4 for a\n', False)
 
230
        builder.commit(b'Joe Foo <joe@foo.com>', u'Third', merge=[r2a], base=r2b)
 
231
        builder.finish()
 
232
 
 
233
        # Check that bzr log does not fail and includes the revision.
 
234
        output, error = self.run_bzr(['log', '-n2', 'a'])
 
235
        self.assertEqual(error, '')
 
236
        self.assertIn('Second a', output)
 
237
        self.assertIn('Second b', output)
 
238
        self.assertIn('First', output)
 
239
        self.assertIn('Third', output)
 
240
 
 
241
    def test_tags(self):
 
242
        git_repo, commit_sha1 = self.simple_commit()
 
243
        git_repo.refs[b"refs/tags/foo"] = commit_sha1
 
244
 
 
245
        output, error = self.run_bzr(['tags'])
 
246
        self.assertEqual(error, '')
 
247
        self.assertEqual(output, "foo                  1\n")
 
248
 
 
249
    def test_tag(self):
 
250
        self.simple_commit()
 
251
 
 
252
        output, error = self.run_bzr(["tag", "bar"])
 
253
 
 
254
        # bzr <= 2.2 emits this message in the output stream
 
255
        # bzr => 2.3 emits this message in the error stream
 
256
        self.assertEqual(error + output, 'Created tag bar.\n')
 
257
 
 
258
    def test_init_repo(self):
 
259
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
 
260
        self.assertEqual(error, '')
 
261
        self.assertEqual(output, 'Created a standalone tree (format: git)\n')
 
262
 
 
263
    def test_diff_format(self):
 
264
        tree = self.make_branch_and_tree('.')
 
265
        self.build_tree(['a'])
 
266
        tree.add(['a'])
 
267
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
 
268
        self.assertEqual(error, '')
 
269
        # Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
 
270
        # differently.
 
271
        from dulwich import __version__ as dulwich_version
 
272
        if dulwich_version < (0, 19, 12):
 
273
            self.assertEqual(output,
 
274
                             'diff --git /dev/null b/a\n'
 
275
                             'old mode 0\n'
 
276
                             'new mode 100644\n'
 
277
                             'index 0000000..c197bd8 100644\n'
 
278
                             '--- /dev/null\n'
 
279
                             '+++ b/a\n'
 
280
                             '@@ -0,0 +1 @@\n'
 
281
                             '+contents of a\n')
 
282
        else:
 
283
            self.assertEqual(output,
 
284
                             'diff --git a/a b/a\n'
 
285
                             'old file mode 0\n'
 
286
                             'new file mode 100644\n'
 
287
                             'index 0000000..c197bd8 100644\n'
 
288
                             '--- /dev/null\n'
 
289
                             '+++ b/a\n'
 
290
                             '@@ -0,0 +1 @@\n'
 
291
                             '+contents of a\n')
 
292
 
 
293
    def test_git_import_uncolocated(self):
 
294
        r = GitRepo.init("a", mkdir=True)
 
295
        self.build_tree(["a/file"])
 
296
        r.stage("file")
 
297
        r.do_commit(ref=b"refs/heads/abranch",
 
298
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
299
        r.do_commit(ref=b"refs/heads/bbranch",
 
300
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
301
        self.run_bzr(["git-import", "a", "b"])
 
302
        self.assertEqual(
 
303
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
 
304
 
 
305
    def test_git_import(self):
 
306
        r = GitRepo.init("a", mkdir=True)
 
307
        self.build_tree(["a/file"])
 
308
        r.stage("file")
 
309
        r.do_commit(ref=b"refs/heads/abranch",
 
310
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
311
        r.do_commit(ref=b"refs/heads/bbranch",
 
312
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
313
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
314
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
315
        self.assertEqual(set(["abranch", "bbranch"]),
 
316
                         set(ControlDir.open("b").get_branches().keys()))
 
317
 
 
318
    def test_git_import_incremental(self):
 
319
        r = GitRepo.init("a", mkdir=True)
 
320
        self.build_tree(["a/file"])
 
321
        r.stage("file")
 
322
        r.do_commit(ref=b"refs/heads/abranch",
 
323
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
324
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
325
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
326
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
327
        b = ControlDir.open("b")
 
328
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
 
329
 
 
330
    def test_git_import_tags(self):
 
331
        r = GitRepo.init("a", mkdir=True)
 
332
        self.build_tree(["a/file"])
 
333
        r.stage("file")
 
334
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
335
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
 
336
        r[b"refs/tags/atag"] = cid
 
337
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
338
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
339
        b = ControlDir.open("b")
 
340
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
 
341
        self.assertEqual(["atag"],
 
342
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
 
343
 
 
344
    def test_git_import_colo(self):
 
345
        r = GitRepo.init("a", mkdir=True)
 
346
        self.build_tree(["a/file"])
 
347
        r.stage("file")
 
348
        r.do_commit(ref=b"refs/heads/abranch",
 
349
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
350
        r.do_commit(ref=b"refs/heads/bbranch",
 
351
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
352
        self.make_controldir("b", format="development-colo")
 
353
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
354
        self.assertEqual(
 
355
            set([b.name for b in ControlDir.open("b").list_branches()]),
 
356
            set(["abranch", "bbranch"]))
 
357
 
 
358
    def test_git_refs_from_git(self):
 
359
        r = GitRepo.init("a", mkdir=True)
 
360
        self.build_tree(["a/file"])
 
361
        r.stage("file")
 
362
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
363
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
 
364
        r[b"refs/tags/atag"] = cid
 
365
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
 
366
        self.assertEqual(stderr, "")
 
367
        self.assertEqual(stdout,
 
368
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
 
369
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
 
370
 
 
371
    def test_git_refs_from_bzr(self):
 
372
        tree = self.make_branch_and_tree('a')
 
373
        self.build_tree(["a/file"])
 
374
        tree.add(["file"])
 
375
        revid = tree.commit(
 
376
            committer=b"Joe <joe@example.com>", message=b"Dummy")
 
377
        tree.branch.tags.set_tag("atag", revid)
 
378
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
 
379
        self.assertEqual(stderr, "")
 
380
        self.assertTrue("refs/tags/atag -> " in stdout)
 
381
        self.assertTrue("HEAD -> " in stdout)
 
382
 
 
383
    def test_check(self):
 
384
        r = GitRepo.init("gitr", mkdir=True)
 
385
        self.build_tree_contents([("gitr/foo", b"hello from git")])
 
386
        r.stage("foo")
 
387
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
 
388
        out, err = self.run_bzr(["check", "gitr"])
 
389
        self.maxDiff = None
 
390
        self.assertEqual(out, '')
 
391
        self.assertTrue(err.endswith, '3 objects\n')
 
392
 
 
393
 
 
394
class ShallowTests(ExternalBase):
 
395
 
 
396
    def setUp(self):
 
397
        super(ShallowTests, self).setUp()
 
398
        # Smoke test for "bzr log" in a git repository with shallow depth.
 
399
        self.repo = GitRepo.init('gitr', mkdir=True)
 
400
        self.build_tree_contents([("gitr/foo", b"hello from git")])
 
401
        self.repo.stage("foo")
 
402
        self.repo.do_commit(
 
403
            b"message", committer=b"Somebody <user@example.com>",
 
404
            author=b"Somebody <user@example.com>",
 
405
            commit_timestamp=1526330165, commit_timezone=0,
 
406
            author_timestamp=1526330165, author_timezone=0,
 
407
            merge_heads=[b'aa' * 20])
 
408
 
 
409
    def test_log_shallow(self):
 
410
        # Check that bzr log does not fail and includes the revision.
 
411
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
 
412
        self.assertEqual(
 
413
            error, 'brz: ERROR: Further revision history missing.\n')
 
414
        self.assertEqual(output,
 
415
                         '------------------------------------------------------------\n'
 
416
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
 
417
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
 
418
                         'committer: Somebody <user@example.com>\n'
 
419
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
 
420
                         'message:\n'
 
421
                         '  message\n')
 
422
 
 
423
    def test_version_info_rio(self):
 
424
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
 
425
        self.assertEqual(error, '')
 
426
        self.assertNotIn('revno:', output)
 
427
 
 
428
    def test_version_info_python(self):
 
429
        output, error = self.run_bzr(['version-info', '--python', 'gitr'])
 
430
        self.assertEqual(error, '')
 
431
        self.assertNotIn('revno:', output)
 
432
 
 
433
    def test_version_info_custom_with_revno(self):
 
434
        output, error = self.run_bzr(
 
435
            ['version-info', '--custom',
 
436
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
 
437
        self.assertEqual(
 
438
            error, 'brz: ERROR: Variable {revno} is not available.\n')
 
439
        self.assertEqual(output, 'VERSION_INFO r')
 
440
 
 
441
    def test_version_info_custom_without_revno(self):
 
442
        output, error = self.run_bzr(
 
443
            ['version-info', '--custom', '--template=VERSION_INFO \n',
 
444
             'gitr'])
 
445
        self.assertEqual(error, '')
 
446
        self.assertEqual(output, 'VERSION_INFO \n')
 
447
 
 
448
 
 
449
class SwitchTests(ExternalBase):
 
450
 
 
451
    def test_switch_branch(self):
 
452
        # Create a git repository with a revision.
 
453
        repo = GitRepo.init(self.test_dir)
 
454
        builder = tests.GitBranchBuilder()
 
455
        builder.set_branch(b'refs/heads/oldbranch')
 
456
        builder.set_file('a', b'text for a\n', False)
 
457
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
458
        builder.set_branch(b'refs/heads/newbranch')
 
459
        builder.reset()
 
460
        builder.set_file('a', b'text for new a\n', False)
 
461
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
462
        builder.finish()
 
463
 
 
464
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
 
465
 
 
466
        repo.reset_index()
 
467
 
 
468
        output, error = self.run_bzr('switch oldbranch')
 
469
        self.assertEqual(output, '')
 
470
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
 
471
 
 
472
        self.assertFileEqual("text for a\n", 'a')
 
473
        tree = WorkingTree.open('.')
 
474
        with tree.lock_read():
 
475
            basis_tree = tree.basis_tree()
 
476
            with basis_tree.lock_read():
 
477
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
 
478
 
 
479
 
 
480
class SwitchScriptTests(TestCaseWithTransportAndScript):
 
481
 
 
482
    def test_switch_preserves(self):
 
483
        # See https://bugs.launchpad.net/brz/+bug/1820606
 
484
        self.run_script("""
 
485
$ brz init --git r
 
486
Created a standalone tree (format: git)
 
487
$ cd r
 
488
$ echo original > file.txt
 
489
$ brz add
 
490
adding file.txt
 
491
$ brz ci -q -m "Initial"
 
492
$ echo "entered on master branch" > file.txt
 
493
$ brz stat
 
494
modified:
 
495
  file.txt
 
496
$ brz switch -b other
 
497
2>Tree is up to date at revision 1.
 
498
2>Switched to branch other
 
499
$ cat file.txt
 
500
entered on master branch
 
501
""")
 
502
 
 
503
 
 
504
class GrepTests(ExternalBase):
 
505
 
 
506
    def test_simple_grep(self):
 
507
        tree = self.make_branch_and_tree('.', format='git')
 
508
        self.build_tree_contents([('a', 'text for a\n')])
 
509
        tree.add(['a'])
 
510
        output, error = self.run_bzr('grep text')
 
511
        self.assertEqual(output, 'a:text for a\n')
 
512
        self.assertEqual(error, '')
 
513
 
 
514
 
 
515
class ReconcileTests(ExternalBase):
 
516
 
 
517
    def test_simple_reconcile(self):
 
518
        tree = self.make_branch_and_tree('.', format='git')
 
519
        self.build_tree_contents([('a', 'text for a\n')])
 
520
        tree.add(['a'])
 
521
        output, error = self.run_bzr('reconcile')
 
522
        self.assertContainsRe(
 
523
            output,
 
524
            'Reconciling branch file://.*\n'
 
525
            'Reconciling repository file://.*\n'
 
526
            'Reconciliation complete.\n')
 
527
        self.assertEqual(error, '')
 
528
 
 
529
 
 
530
class StatusTests(ExternalBase):
 
531
 
 
532
    def test_empty_dir(self):
 
533
        tree = self.make_branch_and_tree('.', format='git')
 
534
        self.build_tree(['a/', 'a/foo'])
 
535
        self.build_tree_contents([('.gitignore', 'foo\n')])
 
536
        tree.add(['.gitignore'])
 
537
        tree.commit('add ignore')
 
538
        output, error = self.run_bzr('st')
 
539
        self.assertEqual(output, '')
 
540
        self.assertEqual(error, '')
 
541
 
 
542
 
 
543
class StatsTests(ExternalBase):
 
544
 
 
545
    def test_simple_stats(self):
 
546
        self.requireFeature(PluginLoadedFeature('stats'))
 
547
        tree = self.make_branch_and_tree('.', format='git')
 
548
        self.build_tree_contents([('a', 'text for a\n')])
 
549
        tree.add(['a'])
 
550
        tree.commit('a commit', committer='Somebody <somebody@example.com>')
 
551
        output, error = self.run_bzr('stats')
 
552
        self.assertEqual(output, '   1 Somebody <somebody@example.com>\n')
 
553
 
 
554
 
 
555
class GitObjectsTests(ExternalBase):
 
556
 
 
557
    def run_simple(self, format):
 
558
        tree = self.make_branch_and_tree('.', format=format)
 
559
        self.build_tree(['a/', 'a/foo'])
 
560
        tree.add(['a'])
 
561
        tree.commit('add a')
 
562
        output, error = self.run_bzr('git-objects')
 
563
        shas = list(output.splitlines())
 
564
        self.assertEqual([40, 40], [len(s) for s in shas])
 
565
        self.assertEqual(error, '')
 
566
 
 
567
        output, error = self.run_bzr('git-object %s' % shas[0])
 
568
        self.assertEqual('', error)
 
569
 
 
570
    def test_in_native(self):
 
571
        self.run_simple(format='git')
 
572
 
 
573
    def test_in_bzr(self):
 
574
        self.run_simple(format='2a')
 
575
 
 
576
 
 
577
class GitApplyTests(ExternalBase):
 
578
 
 
579
    def test_apply(self):
 
580
        b = self.make_branch_and_tree('.')
 
581
 
 
582
        with open('foo.patch', 'w') as f:
 
583
            f.write("""\
 
584
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
 
585
From: Dmitry Bogatov <KAction@debian.org>
 
586
Date: Fri, 8 Feb 2019 23:28:30 +0000
 
587
Subject: [PATCH] Add fixed for out-of-date-standards-version
 
588
 
 
589
---
 
590
 message           | 3 +++
 
591
 1 files changed, 14 insertions(+)
 
592
 create mode 100644 message
 
593
 
 
594
diff --git a/message b/message
 
595
new file mode 100644
 
596
index 0000000..05ec0b1
 
597
--- /dev/null
 
598
+++ b/message
 
599
@@ -0,0 +1,3 @@
 
600
+Update standards version, no changes needed.
 
601
+Certainty: certain
 
602
+Fixed-Lintian-Tags: out-of-date-standards-version
 
603
""")
 
604
        output, error = self.run_bzr('git-apply foo.patch')
 
605
        self.assertContainsRe(
 
606
            error,
 
607
            'Committing to: .*\n'
 
608
            'Committed revision 1.\n')